/*
 * Portions of this file Copyright 1999-2005 University of Chicago
 * Portions of this file Copyright 1999-2005 The University of Southern California.
 *
 * This file or a portion of this file is licensed under the
 * terms of the Globus Toolkit Public License, found at
 * http://www.globus.org/toolkit/download/license.html.
 * If you redistribute this file, with or without
 * modifications, you must include this notice in the file.
 */


#ifndef _GLOBUS_SOAP_MESSAGE_UTILS_H_
#define _GLOBUS_SOAP_MESSAGE_UTILS_H_

#include "globus_common.h"

EXTERN_C_BEGIN

extern globus_module_descriptor_t globus_i_soap_message_module;

#define GLOBUS_SOAP_MESSAGE_MODULE &globus_i_soap_message_module

enum
{
    GLOBUS_SOAP_MESSAGE_ERROR_TYPE_NULL_PARAM = 1024,
    GLOBUS_SOAP_MESSAGE_ERROR_TYPE_OUT_OF_MEMORY,
    GLOBUS_SOAP_MESSAGE_ERROR_TYPE_SERIALIZE_FAILED,
    GLOBUS_SOAP_MESSAGE_ERROR_TYPE_SERIALIZE_ANYATTRS_FAILED,
    GLOBUS_SOAP_MESSAGE_ERROR_TYPE_SERIALIZE_NAMESPACE_FAILED,
    GLOBUS_SOAP_MESSAGE_ERROR_TYPE_DESERIALIZE_FAILED,
    GLOBUS_SOAP_MESSAGE_ERROR_TYPE_DESERIALIZE_ANYATTRS_FAILED,
    GLOBUS_SOAP_MESSAGE_ERROR_TYPE_COPY_ANYATTRS_FAILED,
    GLOBUS_SOAP_MESSAGE_ERROR_TYPE_FAILED_REGISTRY_LOOKUP,
    GLOBUS_SOAP_MESSAGE_ERROR_TYPE_ELEMENT_NOT_FOUND,
    GLOBUS_SOAP_MESSAGE_ERROR_TYPE_ATTRIBUTE_NOT_FOUND,
    GLOBUS_SOAP_MESSAGE_ERROR_TYPE_FAILED_NEXT_NODE,
    GLOBUS_SOAP_MESSAGE_ERROR_TYPE_FAILED_ELEMENT,
    GLOBUS_SOAP_MESSAGE_ERROR_TYPE_FAILED_WITH_TEXT,
    GLOBUS_SOAP_MESSAGE_ERROR_TYPE_FAILED_END_ELEMENT,    
    GLOBUS_SOAP_MESSAGE_ERROR_TYPE_FAILED_CONTENT,
    GLOBUS_SOAP_MESSAGE_ERROR_TYPE_FAILED_ATTRIBUTE,
    GLOBUS_SOAP_MESSAGE_ERROR_TYPE_MESSAGE_INVALID,
    GLOBUS_SOAP_MESSAGE_ERROR_TYPE_DESERIALIZE_CONTENT_FAILED,
    GLOBUS_SOAP_MESSAGE_ERROR_TYPE_INIT_FAILED,
    GLOBUS_SOAP_MESSAGE_ERROR_TYPE_WITH_MARKER,
    GLOBUS_SOAP_MESSAGE_ERROR_TYPE_SETTING_ID,
    GLOBUS_SOAP_MESSAGE_ERROR_TYPE_WITH_MARKERS,
    GLOBUS_SOAP_MESSAGE_ERROR_TYPE_PARSER_FAILED,
    GLOBUS_SOAP_MESSAGE_ERROR_TYPE_NO_TYPE_FOUND,
    GLOBUS_SOAP_MESSAGE_ERROR_TYPE_UNDEFINED_NAMESPACE,
    GLOBUS_SOAP_MESSAGE_ERROR_TYPE_ATTR_USE_REQUIRED,
    GLOBUS_SOAP_MESSAGE_ERROR_TYPE_CLIENT_REQUEST_FAILED,
    GLOBUS_SOAP_MESSAGE_ERROR_TYPE_CLIENT_RESPONSE_FAILED,
    GLOBUS_SOAP_MESSAGE_ERROR_TYPE_FAILED_TRANSPORT,
    GLOBUS_SOAP_MESSAGE_ERROR_TYPE_FAILED_CLIENT_INIT,
    GLOBUS_SOAP_MESSAGE_ERROR_TYPE_FAILED_REGISTRY_POPULATE,
    GLOBUS_SOAP_MESSAGE_ERROR_TYPE_UNEXPECTED_ELEMENT,
    GLOBUS_SOAP_MESSAGE_ERROR_TYPE_MUST_UNDERSTAND,
    GLOBUS_SOAP_MESSAGE_ERROR_TYPE_BAD_REQUEST,
    GLOBUS_SOAP_MESSAGE_ERROR_TYPE_FAILED_RESPONSE,
    GLOBUS_SOAP_MESSAGE_ERROR_TYPE_EXPECTED_FAULT,
    GLOBUS_SOAP_MESSAGE_ERROR_TYPE_FAULT,
    GLOBUS_SOAP_MESSAGE_ERROR_TYPE_COPY_FAILED,
    GLOBUS_SOAP_MESSAGE_ERROR_TYPE_FAILED_RESOURCE_GET,
    GLOBUS_SOAP_MESSAGE_ERROR_TYPE_CLIENT_ALREADY_INVOKED,
    GLOBUS_SOAP_MESSAGE_ERROR_TYPE_TOO_MANY_REFERENCE_PROPERTIES,
    GLOBUS_SOAP_MESSAGE_ERROR_TYPE_NO_REFERENCE_PROPERTIES,
    GLOBUS_SOAP_MESSAGE_ERROR_TYPE_NO_XSI_TYPE_ATTR,
    GLOBUS_SOAP_MESSAGE_ERROR_TYPE_ARRAY_OUT_OF_BOUNDS
};

#define GLOBUS_SOAP_MESSAGE_STATUS_ELEMENT_NOT_FOUND   0xFFFFFFF1
#define GLOBUS_SOAP_MESSAGE_STATUS_ATTRIBUTE_NOT_FOUND 0xFFFFFFF2
#define GLOBUS_SOAP_MESSAGE_STATUS_FAILED_ELEMENT      0xFFFFFFF3
#define GLOBUS_SOAP_MESSAGE_STATUS_FAILED_WITH_TEXT    0xFFFFFFF4
#define GLOBUS_SOAP_MESSAGE_STATUS_FAILED_END_ELEMENT  0xFFFFFFF5

GlobusDebugDeclare(GLOBUS_SOAP_MESSAGE);

#define GLOBUS_SOAP_MESSAGE_DEBUG_MESSAGES  1
#define GLOBUS_SOAP_MESSAGE_DEBUG_INFO      2
#define GLOBUS_SOAP_MESSAGE_DEBUG_DEBUG     4
#define GLOBUS_SOAP_MESSAGE_DEBUG_TRACE     8
#define GLOBUS_SOAP_MESSAGE_DEBUG_WARN      16
#define GLOBUS_SOAP_MESSAGE_DEBUG_REGISTRY  32
#define GLOBUS_SOAP_MESSAGE_DEBUG_WILDCARDS 64

#define GlobusSoapMessageDebug(LEVEL) \
    (GlobusDebugTrue(GLOBUS_SOAP_MESSAGE, LEVEL))

#define GlobusSoapMessageDebugPrintf(LEVEL, MESSAGE) \
    GlobusDebugPrintf(GLOBUS_SOAP_MESSAGE, LEVEL, MESSAGE)

#define GlobusSoapMessageDebugEnter() \
    GlobusSoapMessageDebugPrintf(GLOBUS_SOAP_MESSAGE_DEBUG_TRACE, \
                                 ("[%s] Entering\n", _globus_func_name))

#define GlobusSoapMessageDebugExit() \
    GlobusSoapMessageDebugPrintf(GLOBUS_SOAP_MESSAGE_DEBUG_TRACE, \
                                 ("[%s] Exiting\n", _globus_func_name))

#define GlobusSoapMessageDebugError(ERROR) \
    GlobusDebugPrintf(GLOBUS_SOAP_MESSAGE, GLOBUS_SOAP_MESSAGE_DEBUG_WARN, \
                      (globus_error_print_chain(globus_error_peek(ERROR))))

#define GLOBUS_SOAP_MESSAGE_ERROR_OUT_OF_MEMORY_OBJECT \
        globus_error_construct_error( \
            GLOBUS_SOAP_MESSAGE_MODULE, \
            NULL, \
            GLOBUS_SOAP_MESSAGE_ERROR_TYPE_OUT_OF_MEMORY, \
            __FILE__, \
            _globus_func_name, \
            __LINE__, \
            "Out of memory")

#define GLOBUS_SOAP_MESSAGE_ERROR_NULL_PARAM_OBJECT \
        globus_error_construct_error( \
            GLOBUS_SOAP_MESSAGE_MODULE, \
            NULL, \
            GLOBUS_SOAP_MESSAGE_ERROR_TYPE_NULL_PARAM, \
            __FILE__, \
            _globus_func_name, \
            __LINE__, \
            "Null parameter")

#define GLOBUS_SOAP_MESSAGE_ERROR_SERIALIZE_FAILED_OBJECT( \
    cause, causal_string, qname) \
        globus_error_construct_error( \
            GLOBUS_SOAP_MESSAGE_MODULE, \
            cause ? globus_error_get(cause) : NULL, \
            GLOBUS_SOAP_MESSAGE_ERROR_TYPE_SERIALIZE_FAILED, \
            __FILE__, \
            _globus_func_name, \
            __LINE__, \
            "Serialization of {%s}%s failed%s%s", \
            (qname ? ((char *)(qname)->Namespace) : ""), \
            (qname ? ((char *)(qname)->local) : ""), \
            (causal_string ? ": " : ""), \
            (causal_string ? causal_string : ""))

#define GLOBUS_SOAP_MESSAGE_ERROR_COPY_FAILED_OBJECT( \
    cause, causal_string, qname) \
        globus_error_construct_error( \
            GLOBUS_SOAP_MESSAGE_MODULE, \
            cause ? globus_error_get(cause) : NULL, \
            GLOBUS_SOAP_MESSAGE_ERROR_TYPE_COPY_FAILED, \
            __FILE__, \
            _globus_func_name, \
            __LINE__, \
            "Copy of {%s}%s failed%s%s", \
            (qname ? ((char *)(qname)->Namespace) : ""), \
            (qname ? ((char *)(qname)->local) : ""), \
            (causal_string ? ": " : ""), \
            (causal_string ? causal_string : ""))

#define GLOBUS_SOAP_MESSAGE_ERROR_SERIALIZE_ANYATTRS_FAILED_OBJECT( \
    cause, causal_string) \
        globus_error_construct_error( \
            GLOBUS_SOAP_MESSAGE_MODULE, \
            cause ? globus_error_get(cause) : NULL, \
            GLOBUS_SOAP_MESSAGE_ERROR_TYPE_SERIALIZE_ANYATTRS_FAILED, \
            __FILE__, \
            _globus_func_name, \
            __LINE__, \
            "Serialization of anyAttributes failed%s%s", \
            (causal_string ? ": " : ""), \
            (causal_string ? causal_string : ""))

#define GLOBUS_SOAP_MESSAGE_ERROR_SERIALIZE_NAMESPACE_FAILED_OBJECT(    \
    ns, prefix)                                                         \
        globus_error_construct_error(                                   \
            GLOBUS_SOAP_MESSAGE_MODULE,                                 \
            NULL,                                                       \
            GLOBUS_SOAP_MESSAGE_ERROR_TYPE_SERIALIZE_NAMESPACE_FAILED,  \
            __FILE__,                                                   \
            _globus_func_name,                                          \
            __LINE__,                                                   \
            "Serialization of namespace: %s:%s failed",                 \
            (ns ? (const char *)ns : ""),                               \
            (prefix ? (const char *)prefix : ""))

#define GLOBUS_SOAP_MESSAGE_ERROR_SERIALIZE_ELEMENT_END_FAILED_OBJECT( \
    causal_string) \
        globus_error_construct_error( \
            GLOBUS_SOAP_MESSAGE_MODULE, \
            NULL, \
            GLOBUS_SOAP_MESSAGE_ERROR_TYPE_SERIALIZE_FAILED, \
            __FILE__, \
            _globus_func_name, \
            __LINE__, \
            "Serialization of end element failed: %s", \
            (causal_string ? ": " : ""), \
            (causal_string ? causal_string : ""))

#define GLOBUS_SOAP_MESSAGE_ERROR_DESERIALIZE_FAILED_OBJECT(cause, qname) \
        globus_error_construct_error( \
            GLOBUS_SOAP_MESSAGE_MODULE, \
            cause ? globus_error_get(cause) : NULL, \
            GLOBUS_SOAP_MESSAGE_ERROR_TYPE_DESERIALIZE_FAILED, \
            __FILE__, \
            _globus_func_name, \
            __LINE__, \
            "Deserialization of {%s}%s failed.", \
            (qname ? ((char *)((qname)->Namespace)) : ""), \
            (qname ? ((char *)((qname)->local)) : ""))

#define GLOBUS_SOAP_MESSAGE_ERROR_DESERIALIZE_FAILED_OBJECT(cause, qname) \
        globus_error_construct_error( \
            GLOBUS_SOAP_MESSAGE_MODULE, \
            cause ? globus_error_get(cause) : NULL, \
            GLOBUS_SOAP_MESSAGE_ERROR_TYPE_DESERIALIZE_FAILED, \
            __FILE__, \
            _globus_func_name, \
            __LINE__, \
            "Deserialization of {%s}%s failed.", \
            (qname ? ((char *)((qname)->Namespace)) : ""), \
            (qname ? ((char *)((qname)->local)) : ""))

#define GLOBUS_SOAP_MESSAGE_ERROR_DESERIALIZE_ANYATTRS_FAILED_OBJECT( \
    cause, causal_string) \
        globus_error_construct_error( \
            GLOBUS_SOAP_MESSAGE_MODULE, \
            cause ? globus_error_get(cause) : NULL, \
            GLOBUS_SOAP_MESSAGE_ERROR_TYPE_DESERIALIZE_ANYATTRS_FAILED, \
            __FILE__, \
            _globus_func_name, \
            __LINE__, \
            "Deserialization of anyAttributes failed%s%s", \
            (causal_string ? ": " : ""), \
            (causal_string ? causal_string : ""))

#define GLOBUS_SOAP_MESSAGE_ERROR_COPY_ANYATTRS_FAILED_OBJECT( \
    cause, causal_string) \
        globus_error_construct_error( \
            GLOBUS_SOAP_MESSAGE_MODULE, \
            cause ? globus_error_get(cause) : NULL, \
            GLOBUS_SOAP_MESSAGE_ERROR_TYPE_COPY_ANYATTRS_FAILED, \
            __FILE__, \
            _globus_func_name, \
            __LINE__, \
            "Copy of anyAttributes failed%s%s", \
            (causal_string ? ": " : ""), \
            (causal_string ? causal_string : ""))

#define GLOBUS_SOAP_MESSAGE_ERROR_FAILED_REGISTRY_LOOKUP_OBJECT(cause, qname) \
        globus_error_construct_error( \
            GLOBUS_SOAP_MESSAGE_MODULE, \
            cause ? globus_error_get(cause) : NULL, \
            GLOBUS_SOAP_MESSAGE_ERROR_TYPE_FAILED_REGISTRY_LOOKUP, \
            __FILE__, \
            _globus_func_name, \
            __LINE__, \
            "Failed to find type info in registry for type: {%s}%s", \
            (qname)->Namespace, (qname)->local)

#define GLOBUS_SOAP_MESSAGE_ERROR_DESERIALIZE_CONTENT_FAILED_OBJECT( \
    qname, content) \
        globus_error_construct_error( \
            GLOBUS_SOAP_MESSAGE_MODULE, \
            NULL, \
            GLOBUS_SOAP_MESSAGE_ERROR_TYPE_DESERIALIZE_CONTENT_FAILED, \
            __FILE__, \
            _globus_func_name, \
            __LINE__, \
            "Failed deserialization of content \"%s\" {%s}%s type.", \
            content, (qname)->Namespace ? (qname)->Namespace : "", \
                (qname)->local ? (qname)->local : "")

#define GLOBUS_SOAP_MESSAGE_ERROR_ELEMENT_NOT_FOUND_OBJECT(expected, actual) \
        globus_error_construct_error( \
            GLOBUS_SOAP_MESSAGE_MODULE, \
            NULL, \
            GLOBUS_SOAP_MESSAGE_ERROR_TYPE_ELEMENT_NOT_FOUND, \
            __FILE__, \
            _globus_func_name, \
            __LINE__, \
            "Found %s%s%s%s element when expected %s%s%s%s.", \
                (actual)->Namespace ? "{" : "", \
                (actual)->Namespace ? (actual)->Namespace : "", \
                (actual)->Namespace ? "}" : "", \
                (actual)->local ? (actual)->local : "",\
                (expected)->Namespace ? "{" : "", \
                (expected)->Namespace ? (expected)->Namespace : "", \
                (expected)->Namespace ? "}" : "", \
                (expected)->local ? (expected)->local : "")

#define GLOBUS_SOAP_MESSAGE_ERROR_ATTRIBUTE_NOT_FOUND_OBJECT(qname) \
        globus_error_construct_error( \
            GLOBUS_SOAP_MESSAGE_MODULE, \
            NULL, \
            GLOBUS_SOAP_MESSAGE_ERROR_TYPE_ATTRIBUTE_NOT_FOUND, \
            __FILE__, \
            _globus_func_name, \
            __LINE__, \
            "Attribute %s%s%s%s not found.", \
            (qname)->Namespace ? "{" : "", \
            (qname)->Namespace ? (qname)->Namespace : "", \
            (qname)->Namespace ? "}" : "", \
            (qname)->local ? (qname)->local : "")

#define GLOBUS_SOAP_MESSAGE_ERROR_FAILED_NEXT_NODE_OBJECT(cause) \
        globus_error_construct_error( \
            GLOBUS_SOAP_MESSAGE_MODULE, \
            (cause ? globus_error_get(cause) : NULL), \
            GLOBUS_SOAP_MESSAGE_ERROR_TYPE_FAILED_NEXT_NODE, \
            __FILE__, \
            _globus_func_name, \
            __LINE__, \
            "XML parser failed to get the next node in the message")

#define GLOBUS_SOAP_MESSAGE_ERROR_FAILED_ELEMENT_OBJECT \
        globus_error_construct_error( \
            GLOBUS_SOAP_MESSAGE_MODULE, \
            NULL, \
            GLOBUS_SOAP_MESSAGE_ERROR_TYPE_FAILED_ELEMENT, \
            __FILE__, \
            _globus_func_name, \
            __LINE__, \
            "Unexpected node in message while  " \
            "looking for a begin element")

#define GLOBUS_SOAP_MESSAGE_ERROR_FAILED_WITH_TEXT_OBJECT(text) \
        globus_error_construct_error( \
            GLOBUS_SOAP_MESSAGE_MODULE, \
            NULL, \
            GLOBUS_SOAP_MESSAGE_ERROR_TYPE_FAILED_WITH_TEXT, \
            __FILE__, \
            _globus_func_name, \
            __LINE__, \
            "Expected element node, found TEXT node '%s'", \
            text ? (char *) text : (char *) "")

#define GLOBUS_SOAP_MESSAGE_ERROR_FAILED_END_ELEMENT_OBJECT(element) \
        globus_error_construct_error( \
            GLOBUS_SOAP_MESSAGE_MODULE, \
            NULL, \
            GLOBUS_SOAP_MESSAGE_ERROR_TYPE_FAILED_END_ELEMENT, \
            __FILE__, \
            _globus_func_name, \
            __LINE__, \
            "Unexpected %s%s%s%s element in message while " \
            "looking for an end tag", \
            (element)->Namespace ? "{" : "", \
            (element)->Namespace ? (element)->Namespace : "", \
            (element)->Namespace ? "}" : "", \
            (element)->local ? (element)->local : "")

#define GLOBUS_SOAP_MESSAGE_ERROR_FAILED_CONTENT_OBJECT \
        globus_error_construct_error( \
            GLOBUS_SOAP_MESSAGE_MODULE, \
            NULL, \
            GLOBUS_SOAP_MESSAGE_ERROR_TYPE_FAILED_CONTENT, \
            __FILE__, \
            _globus_func_name, \
            __LINE__, \
            "Invalid message format.  Element has no content.")

#define GLOBUS_SOAP_MESSAGE_ERROR_FAILED_ATTRIBUTE_OBJECT       \
        globus_error_construct_error(                           \
            GLOBUS_SOAP_MESSAGE_MODULE,                         \
            NULL,                                               \
            GLOBUS_SOAP_MESSAGE_ERROR_TYPE_FAILED_ATTRIBUTE,    \
            __FILE__,                                           \
            _globus_func_name,                                  \
            __LINE__,                                           \
            "Element does not contain the expected attribute.")

#define GLOBUS_SOAP_MESSAGE_ERROR_INIT_FAILED_OBJECT(error_str)         \
        globus_error_construct_error(                                   \
            GLOBUS_SOAP_MESSAGE_MODULE,                                 \
            NULL,                                                       \
            GLOBUS_SOAP_MESSAGE_ERROR_TYPE_INIT_FAILED,                 \
            __FILE__,                                                   \
            _globus_func_name,                                          \
            __LINE__,                                                   \
            "Failed to initialize soap message handle: %s", error_str)

#define GLOBUS_SOAP_MESSAGE_ERROR_WITH_MARKER_OBJECT(   \
    cause, format_str, marker)                          \
        globus_error_construct_error(                   \
            GLOBUS_SOAP_MESSAGE_MODULE,                 \
            cause ? globus_error_get(cause) : NULL,     \
            GLOBUS_SOAP_MESSAGE_ERROR_TYPE_WITH_MARKER, \
            __FILE__,                                   \
            _globus_func_name,                          \
            __LINE__,                                   \
            format_str, marker)

#define GLOBUS_SOAP_MESSAGE_ERROR_SETTING_ID_OBJECT(    \
    cause)                                              \
        globus_error_construct_error(                   \
            GLOBUS_SOAP_MESSAGE_MODULE,                 \
            cause ? globus_error_get(cause) : NULL,     \
            GLOBUS_SOAP_MESSAGE_ERROR_TYPE_SETTING_ID,  \
            __FILE__,                                   \
            _globus_func_name,                          \
            __LINE__,                                   \
            "Failed to set marker for Id attribute")

#define GLOBUS_SOAP_MESSAGE_ERROR_WITH_MARKERS_OBJECT(          \
    cause, format_str, marker1, marker2)                        \
        globus_error_construct_error(                           \
            GLOBUS_SOAP_MESSAGE_MODULE,                         \
            cause ? globus_error_get(cause) : NULL,             \
            GLOBUS_SOAP_MESSAGE_ERROR_TYPE_WITH_MARKERS,        \
            __FILE__,                                           \
            _globus_func_name,                                  \
            __LINE__,                                           \
            format_str, marker1, marker2)

#define GLOBUS_SOAP_MESSAGE_ERROR_PARSER_FAILED_OBJECT(                 \
    message, lineno, baseuri)                                           \
        globus_error_construct_error(                                   \
            GLOBUS_SOAP_MESSAGE_MODULE,                                 \
            NULL,                                                       \
            GLOBUS_SOAP_MESSAGE_ERROR_TYPE_PARSER_FAILED,               \
            __FILE__,                                                   \
            _globus_func_name,                                          \
            __LINE__,                                                   \
            "Parser Failed %s", \
            (message ? message : ""))

#define GLOBUS_SOAP_MESSAGE_ERROR_NO_TYPE_FOUND_OBJECT                  \
        globus_error_construct_error(                                   \
            GLOBUS_SOAP_MESSAGE_MODULE,                                 \
            NULL,                                                       \
            GLOBUS_SOAP_MESSAGE_ERROR_TYPE_NO_TYPE_FOUND,               \
            __FILE__,                                                   \
            _globus_func_name,                                          \
            __LINE__,                                                   \
            "xsd:any element does not contain xsi:type attribute")

#define GLOBUS_SOAP_MESSAGE_ERROR_UNDEFINED_NAMESPACE_OBJECT(           \
    type_prefix)                                                        \
        globus_error_construct_error(                                   \
            GLOBUS_SOAP_MESSAGE_MODULE,                                 \
            NULL,                                                       \
            GLOBUS_SOAP_MESSAGE_ERROR_TYPE_UNDEFINED_NAMESPACE,         \
            __FILE__,                                                   \
            _globus_func_name,                                          \
            __LINE__,                                                   \
            "Namespace prefix %s does not refer "                       \
            "to any namespace in message",                              \
            type_prefix)

#define GLOBUS_SOAP_MESSAGE_ERROR_ATTR_USE_REQUIRED_OBJECT(             \
    attrib_qname, ename)                                                \
        globus_error_construct_error(                                   \
            GLOBUS_SOAP_MESSAGE_MODULE,                                 \
            NULL,                                                       \
            GLOBUS_SOAP_MESSAGE_ERROR_TYPE_ATTR_USE_REQUIRED,           \
            __FILE__,                                                   \
            _globus_func_name,                                          \
            __LINE__,                                                   \
            "%s attribute found.  Schema requires the use of the"       \
            " attribute %s in this element",                            \
            attrib_qname, ename)

#define GLOBUS_SOAP_MESSAGE_ERROR_CLIENT_REQUEST_FAILED_OBJECT(            \
    cause, request)                                                        \
        globus_error_construct_error(                                      \
            GLOBUS_SOAP_MESSAGE_MODULE,                                    \
            (cause ? globus_error_get(cause) : NULL),                      \
            GLOBUS_SOAP_MESSAGE_ERROR_TYPE_CLIENT_REQUEST_FAILED,          \
            __FILE__,                                                      \
            _globus_func_name,                                             \
            __LINE__,                                                      \
            "Failed sending request %s.", request)

#define GLOBUS_SOAP_MESSAGE_ERROR_CLIENT_RESPONSE_FAILED_OBJECT(        \
    cause, response)                                                    \
        globus_error_construct_error(                                   \
            GLOBUS_SOAP_MESSAGE_MODULE,                                 \
            (cause ? globus_error_get(cause) : NULL),                   \
            GLOBUS_SOAP_MESSAGE_ERROR_TYPE_CLIENT_RESPONSE_FAILED,      \
            __FILE__,                                                   \
            _globus_func_name,                                          \
            __LINE__,                                                   \
            "Failed receiving response %s.", response)

#define GLOBUS_SOAP_MESSAGE_ERROR_FAILED_TRANSPORT_OBJECT(              \
    cause, message)                                                     \
        globus_error_construct_error(                                   \
            GLOBUS_SOAP_MESSAGE_MODULE,                                 \
            (cause ? globus_error_get(cause) : NULL),                   \
            GLOBUS_SOAP_MESSAGE_ERROR_TYPE_FAILED_TRANSPORT,            \
            __FILE__,                                                   \
            _globus_func_name,                                          \
            __LINE__,                                                   \
            "SOAP Message transport failed: %s", message)

#define GLOBUS_SOAP_MESSAGE_ERROR_FAILED_CLIENT_INIT_OBJECT(            \
    cause, porttype)                                                    \
        globus_error_construct_error(                                   \
            GLOBUS_SOAP_MESSAGE_MODULE,                                 \
            (cause ? globus_error_get(cause) : NULL),                   \
            GLOBUS_SOAP_MESSAGE_ERROR_TYPE_FAILED_CLIENT_INIT,          \
            __FILE__,                                                   \
            _globus_func_name,                                          \
            __LINE__,                                                   \
            "Failed to intialize client: %s", porttype)

#define GLOBUS_SOAP_MESSAGE_ERROR_FAILED_REGISTRY_POPULATE_OBJECT(      \
    cause, Namespace, local)                                            \
        globus_error_construct_error(                                   \
            GLOBUS_SOAP_MESSAGE_MODULE,                                 \
            (cause ? globus_error_get(cause) : NULL),                   \
            GLOBUS_SOAP_MESSAGE_ERROR_TYPE_FAILED_REGISTRY_POPULATE,    \
            __FILE__,                                                   \
            _globus_func_name,                                          \
            __LINE__,                                                   \
            "Failed to populate registry with type info: {%s}%s",       \
            Namespace, local)

#define GLOBUS_SOAP_MESSAGE_ERROR_UNEXPECTED_ELEMENT_OBJECT(            \
    qname)                                                              \
        globus_error_construct_error(                                   \
            GLOBUS_SOAP_MESSAGE_MODULE,                                 \
            NULL,                                                       \
            GLOBUS_SOAP_MESSAGE_ERROR_TYPE_UNEXPECTED_ELEMENT,          \
            __FILE__,                                                   \
            _globus_func_name,                                          \
            __LINE__,                                                   \
            "Unexpected sub-element found while deserializing: {%s}%s", \
            (qname)->Namespace, (qname)->local)

#define GLOBUS_SOAP_MESSAGE_ERROR_MUST_UNDERSTAND_OBJECT(               \
    cause, element)                                                     \
        globus_error_construct_error(                                   \
            GLOBUS_SOAP_MESSAGE_MODULE,                                 \
            (cause ? globus_error_get(cause) : NULL),                   \
            GLOBUS_SOAP_MESSAGE_ERROR_TYPE_MUST_UNDERSTAND,             \
            __FILE__,                                                   \
            _globus_func_name,                                          \
            __LINE__,                                                   \
            "Loaded message handlers do not understand "                \
            "required header element: %s%s%s%s",                        \
            ((element)->Namespace ? "{" : ""),                          \
            ((element)->Namespace ? element->Namespace : ""),           \
            ((element)->Namespace ? "}" : ""),                          \
            ((element)->local ? element->local : ""))

#define GLOBUS_SOAP_MESSAGE_ERROR_BAD_REQUEST_OBJECT(                   \
    response_code, message)                                             \
        globus_error_construct_error(                                   \
            GLOBUS_SOAP_MESSAGE_MODULE,                                 \
            NULL,                                                       \
            GLOBUS_SOAP_MESSAGE_ERROR_TYPE_BAD_REQUEST,                 \
            __FILE__,                                                   \
            _globus_func_name,                                          \
            __LINE__,                                                   \
            "HTTP Bad Request Error returned from server: %d: %s",      \
            response_code,                                              \
            message)

#define GLOBUS_SOAP_MESSAGE_ERROR_FAILED_RESPONSE_OBJECT(               \
    response_code, message)                                             \
        globus_error_construct_error(                                   \
            GLOBUS_SOAP_MESSAGE_MODULE,                                 \
            NULL,                                                       \
            GLOBUS_SOAP_MESSAGE_ERROR_TYPE_FAILED_RESPONSE,             \
            __FILE__,                                                   \
            _globus_func_name,                                          \
            __LINE__,                                                   \
            "Response Failed Error returned from server: %d: %s",       \
            response_code,                                              \
            message)

#define GLOBUS_SOAP_MESSAGE_ERROR_EXPECTED_FAULT_OBJECT(        \
    result)                                                     \
        globus_error_construct_error(                           \
            GLOBUS_SOAP_MESSAGE_MODULE,                         \
            result ? globus_error_get(result) : NULL,           \
            GLOBUS_SOAP_MESSAGE_ERROR_TYPE_EXPECTED_FAULT,      \
            __FILE__,                                           \
            _globus_func_name,                                  \
            __LINE__,                                           \
            "Expected fault in response")

#define GLOBUS_SOAP_MESSAGE_ERROR_FAILED_RESOURCE_GET_OBJECT(           \
    result, message)                                                    \
        globus_error_construct_error(                                   \
            GLOBUS_SOAP_MESSAGE_MODULE,                                 \
            result ? globus_error_get(result) : NULL,                   \
            GLOBUS_SOAP_MESSAGE_ERROR_TYPE_FAILED_RESOURCE_GET,         \
            __FILE__,                                                   \
            _globus_func_name,                                          \
            __LINE__,                                                   \
            "Failed to get resource from ReferenceProperties: %s",      \
             message)

#define GLOBUS_SOAP_MESSAGE_ERROR_TOO_MANY_REFERENCE_PROPERTIES_OBJECT(     \
    COUNT)                                                                  \
        globus_error_construct_error(                                       \
            GLOBUS_SOAP_MESSAGE_MODULE,                                     \
            result ? globus_error_get(result) : NULL,                       \
            GLOBUS_SOAP_MESSAGE_ERROR_TYPE_TOO_MANY_REFERENCE_PROPERTIES,   \
            __FILE__,                                                       \
            _globus_func_name,                                              \
            __LINE__,                                                       \
            "Failed to get a reference to the resource: Expected a single " \
            "reference property in the EPR but found: %d",                  \
            COUNT)

#define GLOBUS_SOAP_MESSAGE_ERROR_NO_REFERENCE_PROPERTIES_OBJECT        \
        globus_error_construct_error(                                   \
            GLOBUS_SOAP_MESSAGE_MODULE,                                 \
            result ? globus_error_get(result) : NULL,                   \
            GLOBUS_SOAP_MESSAGE_ERROR_TYPE_NO_REFERENCE_PROPERTIES,     \
            __FILE__,                                                   \
            _globus_func_name,                                          \
            __LINE__,                                                   \
            "Failed to get a reference to the resource: No "            \
            "reference properties were found in the EPR")

#define GLOBUS_SOAP_MESSAGE_ERROR_CLIENT_ALREADY_INVOKED_OBJECT         \
        globus_error_construct_error(                                   \
            GLOBUS_SOAP_MESSAGE_MODULE,                                 \
            NULL,                                                       \
            GLOBUS_SOAP_MESSAGE_ERROR_TYPE_CLIENT_ALREADY_INVOKED,      \
            __FILE__,                                                   \
            _globus_func_name,                                          \
            __LINE__,                                                   \
            "A client handle can only invoke one operation at a time")

#define GLOBUS_SOAP_MESSAGE_ERROR_NO_XSI_TYPE_ATTR_OBJECT                   \
        globus_error_construct_error(                                       \
            GLOBUS_SOAP_MESSAGE_MODULE,                                     \
            NULL,                                                           \
            GLOBUS_SOAP_MESSAGE_ERROR_TYPE_NO_XSI_TYPE_ATTR,                \
            __FILE__,                                                       \
            _globus_func_name,                                              \
            __LINE__,                                                       \
            "Failed to deserialize anyType element: no xsi:type attribute")

#define GLOBUS_SOAP_MESSAGE_ERROR_ARRAY_OUT_OF_BOUNDS_OBJECT(__ELEMENT__, \
                                                             __FORMAT__,  \
                                                             __LENGTH__,  \
                                                             __BOUNDS__)  \
    globus_error_construct_error(                                         \
        GLOBUS_SOAP_MESSAGE_MODULE,                                       \
        NULL,                                                             \
        GLOBUS_SOAP_MESSAGE_ERROR_TYPE_ARRAY_OUT_OF_BOUNDS,               \
        __FILE__,                                                         \
        _globus_func_name,                                                \
        __LINE__,                                                         \
        "Array element %s is out of bounds: " __FORMAT__,                 \
        __ELEMENT__,                                                      \
        __LENGTH__,                                                       \
        __BOUNDS__)

#define GlobusSoapMessageErrorOutOfMemory                                \
        globus_error_put(GLOBUS_SOAP_MESSAGE_ERROR_OUT_OF_MEMORY_OBJECT)

#define GlobusSoapMessageErrorNullParam                                 \
        globus_error_put(GLOBUS_SOAP_MESSAGE_ERROR_NULL_PARAM_OBJECT)

#define GlobusSoapMessageErrorSerializeFailed(cause, causal_string, qname)    \
        globus_error_put(                                                     \
            GLOBUS_SOAP_MESSAGE_ERROR_SERIALIZE_FAILED_OBJECT(                \
                cause, causal_string, qname))

#define GlobusSoapMessageErrorCopyFailed(cause, causal_string, qname)   \
        globus_error_put(                                               \
            GLOBUS_SOAP_MESSAGE_ERROR_COPY_FAILED_OBJECT(               \
                cause, causal_string, qname))

#define GlobusSoapMessageErrorSerializeAnyAttrsFailed(                  \
    cause, causal_string)                                               \
        globus_error_put(                                               \
            GLOBUS_SOAP_MESSAGE_ERROR_SERIALIZE_ANYATTRS_FAILED_OBJECT( \
                cause, causal_string))

#define GlobusSoapMessageErrorSerializeNamespaceFailed(                 \
    ns, prefix)                                                         \
    globus_error_put(                                                   \
        GLOBUS_SOAP_MESSAGE_ERROR_SERIALIZE_NAMESPACE_FAILED_OBJECT(    \
            ns, prefix))

#define GlobusSoapMessageErrorSerializeElementEndFailed(causal_string)     \
        globus_error_put(                                                  \
            GLOBUS_SOAP_MESSAGE_ERROR_SERIALIZE_ELEMENT_END_FAILED_OBJECT( \
                causal_string))

#define GlobusSoapMessageErrorDeserializeFailed(cause, qname)		\
        (GlobusSoapMessageStatusCheck(cause) ? cause :			\
        globus_error_put(						\
            GLOBUS_SOAP_MESSAGE_ERROR_DESERIALIZE_FAILED_OBJECT(	\
                cause, qname)))

#define GlobusSoapMessageErrorDeserializeAnyAttrsFailed(cause, causal_string) \
        globus_error_put(                                                     \
            GLOBUS_SOAP_MESSAGE_ERROR_DESERIALIZE_ANYATTRS_FAILED_OBJECT(     \
                cause, causal_string))

#define GlobusSoapMessageErrorCopyAnyAttrsFailed(cause, causal_string)    \
        globus_error_put(                                                 \
            GLOBUS_SOAP_MESSAGE_ERROR_COPY_ANYATTRS_FAILED_OBJECT( \
                cause, causal_string))

#define GlobusSoapMessageErrorFailedRegistryLookup(cause, qname)        \
        globus_error_put(                                               \
            GLOBUS_SOAP_MESSAGE_ERROR_FAILED_REGISTRY_LOOKUP_OBJECT(    \
                cause, qname))

#define GlobusSoapMessageErrorDeserializeContentFailed(qname, content)    \
        globus_error_put(                                                 \
            GLOBUS_SOAP_MESSAGE_ERROR_DESERIALIZE_CONTENT_FAILED_OBJECT(  \
                qname, content))

#define GlobusSoapMessageErrorElementNotFound(verbose, expected, actual)\
        (verbose                                                        \
            ?  globus_error_put(                                        \
                    GLOBUS_SOAP_MESSAGE_ERROR_ELEMENT_NOT_FOUND_OBJECT( \
                        expected, actual))                              \
            : GLOBUS_SOAP_MESSAGE_STATUS_ELEMENT_NOT_FOUND)

#define GlobusSoapMessageErrorAttributeNotFound(verbose, qname)         \
        (verbose                                                        \
            ?  globus_error_put(                                               \
                    GLOBUS_SOAP_MESSAGE_ERROR_ATTRIBUTE_NOT_FOUND_OBJECT(qname)) \
            : GLOBUS_SOAP_MESSAGE_STATUS_ATTRIBUTE_NOT_FOUND)

#define GlobusSoapMessageErrorFailedNextNode(cause)                     \
        globus_error_put(                                               \
            GLOBUS_SOAP_MESSAGE_ERROR_FAILED_NEXT_NODE_OBJECT(cause))

#define GlobusSoapMessageErrorFailedElement()                   \
        globus_error_put(                                       \
            GLOBUS_SOAP_MESSAGE_ERROR_FAILED_ELEMENT_OBJECT)

#define GlobusSoapMessageErrorFailedWithText(verbose, text)             \
        (verbose                                                        \
            ?  globus_error_put(                                        \
                GLOBUS_SOAP_MESSAGE_ERROR_FAILED_WITH_TEXT_OBJECT(text))\
            : GLOBUS_SOAP_MESSAGE_STATUS_FAILED_WITH_TEXT)

#define GlobusSoapMessageErrorFailedEndElement(verbose, unexpected_element) \
        (verbose                                                        \
            ?  globus_error_put(                                        \
                    GLOBUS_SOAP_MESSAGE_ERROR_FAILED_END_ELEMENT_OBJECT(\
                        unexpected_element))                            \
            : GLOBUS_SOAP_MESSAGE_STATUS_FAILED_END_ELEMENT)

#define GlobusSoapMessageErrorFailedContent()                   \
        globus_error_put(                                       \
            GLOBUS_SOAP_MESSAGE_ERROR_FAILED_CONTENT_OBJECT)

#define GlobusSoapMessageErrorFailedAttribute()                 \
        globus_error_put(                                       \
            GLOBUS_SOAP_MESSAGE_ERROR_FAILED_ATTRIBUTE_OBJECT)

#define GlobusSoapMessageErrorInitFailed(error_str)                     \
        globus_error_put(                                               \
            GLOBUS_SOAP_MESSAGE_ERROR_INIT_FAILED_OBJECT(error_str))

#define GlobusSoapMessageErrorWithMarker(result, format_str, marker)    \
        globus_error_put(                                               \
            GLOBUS_SOAP_MESSAGE_ERROR_WITH_MARKER_OBJECT(               \
                result, format_str, marker))

#define GlobusSoapMessageErrorSettingId(result)                 \
        globus_error_put(                                       \
            GLOBUS_SOAP_MESSAGE_ERROR_SETTING_ID_OBJECT(        \
                result))

#define GlobusSoapMessageErrorWithMarkers(                      \
    result, format_str, marker1, marker2)                       \
        globus_error_put(                                       \
            GLOBUS_SOAP_MESSAGE_ERROR_WITH_MARKERS_OBJECT(      \
                result, format_str, marker1, marker2))

#define GlobusSoapMessageErrorParserFailed(                     \
    message, lineno, baseuri)                                   \
        globus_error_put(                                       \
            GLOBUS_SOAP_MESSAGE_ERROR_PARSER_FAILED_OBJECT(     \
                message, lineno, baseuri))

#define GlobusSoapMessageErrorNoTypeFound()                     \
        globus_error_put(                                       \
            GLOBUS_SOAP_MESSAGE_ERROR_NO_TYPE_FOUND_OBJECT)

#define GlobusSoapMessageErrorUndefinedNamespace(                 \
    type_prefix)                                                  \
        globus_error_put(                                         \
            GLOBUS_SOAP_MESSAGE_ERROR_UNDEFINED_NAMESPACE_OBJECT( \
                type_prefix))

#define GlobusSoapMessageErrorAttrUseRequired(                    \
    attr_qname, ename)                                            \
        globus_error_put(                                         \
            GLOBUS_SOAP_MESSAGE_ERROR_ATTR_USE_REQUIRED_OBJECT(   \
                attr_qname, ename))

#define GlobusSoapMessageErrorClientRequestFailed(			\
    cause, request)							\
        (GlobusSoapMessageStatusCheck(cause) ? cause :			\
        globus_error_put(						\
            GLOBUS_SOAP_MESSAGE_ERROR_CLIENT_REQUEST_FAILED_OBJECT(	\
	cause, request)))

#define GlobusSoapMessageErrorClientResponseFailed(			\
    cause, response)							\
        (GlobusSoapMessageStatusCheck(cause) ? cause : 			\
        globus_error_put(						\
            GLOBUS_SOAP_MESSAGE_ERROR_CLIENT_RESPONSE_FAILED_OBJECT(	\
    	        cause, response)))

#define GlobusSoapMessageErrorFailedTransport(                          \
    cause, message)                                                     \
        globus_error_put(                                               \
            GLOBUS_SOAP_MESSAGE_ERROR_FAILED_TRANSPORT_OBJECT(          \
                cause, message))

#define GlobusSoapMessageErrorFailedClientInit(                         \
    cause, porttype)                                                    \
        globus_error_put(                                               \
            GLOBUS_SOAP_MESSAGE_ERROR_FAILED_CLIENT_INIT_OBJECT(        \
                cause, porttype))

#define GlobusSoapMessageErrorFailedRegistryPopulate(                   \
    cause, Namespace, local)                                            \
        globus_error_put(                                               \
            GLOBUS_SOAP_MESSAGE_ERROR_FAILED_REGISTRY_POPULATE_OBJECT(  \
                cause, Namespace, local))

#define GlobusSoapMessageErrorUnexpectedElement(                        \
    qname)                                                              \
        globus_error_put(                                               \
            GLOBUS_SOAP_MESSAGE_ERROR_UNEXPECTED_ELEMENT_OBJECT(        \
                qname))

#define GlobusSoapMessageErrorMustUnderstand(                           \
    result, qname)                                                      \
        globus_error_put(                                               \
            GLOBUS_SOAP_MESSAGE_ERROR_MUST_UNDERSTAND_OBJECT(           \
                result, qname))

#define GlobusSoapMessageErrorBadRequest(                       \
    code, message)                                              \
        globus_error_put(                                       \
            GLOBUS_SOAP_MESSAGE_ERROR_BAD_REQUEST_OBJECT(       \
                code, message))

#define GlobusSoapMessageErrorFailedResponse(                   \
    code, message)                                              \
        globus_error_put(                                       \
            GLOBUS_SOAP_MESSAGE_ERROR_FAILED_RESPONSE_OBJECT(   \
                code, message))

#define GlobusSoapMessageErrorExpectedFault(                    \
    result)                                                     \
        globus_error_put(                                       \
            GLOBUS_SOAP_MESSAGE_ERROR_EXPECTED_FAULT_OBJECT(    \
                result))

#define GlobusSoapMessageErrorFailedResourceGet(                        \
    result, message)                                                    \
        globus_error_put(                                               \
            GLOBUS_SOAP_MESSAGE_ERROR_FAILED_RESOURCE_GET_OBJECT(       \
                result, message))

#define GlobusSoapMessageErrorTooManyReferenceProperties(                   \
    count)                                                                  \
        globus_error_put(                                                   \
            GLOBUS_SOAP_MESSAGE_ERROR_TOO_MANY_REFERENCE_PROPERTIES_OBJECT( \
                count))

#define GlobusSoapMessageErrorNoReferenceProperties()                   \
        globus_error_put(                                               \
            GLOBUS_SOAP_MESSAGE_ERROR_NO_REFERENCE_PROPERTIES_OBJECT)

#define GlobusSoapMessageErrorClientAlreadyInvoked()                    \
    globus_error_put(                                                   \
        GLOBUS_SOAP_MESSAGE_ERROR_CLIENT_ALREADY_INVOKED_OBJECT)

#define GlobusSoapMessageErrorNoXSITypeAttr()                   \
    globus_error_put(                                           \
        GLOBUS_SOAP_MESSAGE_ERROR_NO_XSI_TYPE_ATTR_OBJECT)

#define GlobusSoapMessageErrorArrayBelowBounds(__MINOCCURS__,   \
                                               __LENGTH__,      \
                                               __ELEMENT__)     \
    globus_error_put(                                           \
        GLOBUS_SOAP_MESSAGE_ERROR_ARRAY_OUT_OF_BOUNDS_OBJECT(   \
            __ELEMENT__, "Array length %d < minOccurs of %d",   \
            __LENGTH__, __MINOCCURS__))

#define GlobusSoapMessageErrorArrayAboveBounds(__MINOCCURS__,   \
                                               __LENGTH__,      \
                                               __ELEMENT__)     \
    globus_error_put(                                           \
        GLOBUS_SOAP_MESSAGE_ERROR_ARRAY_OUT_OF_BOUNDS_OBJECT(   \
            __ELEMENT__, "Array length %d > maxOccurs of %d",   \
            __LENGTH__, __MINOCCURS__))

#define GlobusSoapMessageErrorCheck(result, error_type)         \
    (result ? (globus_error_match(globus_error_peek(result),    \
                                 GLOBUS_SOAP_MESSAGE_MODULE,    \
                                 error_type)) : 0)

#define GlobusSoapMessageStatusReservedResult(result) \
        ((result & 0xFFFFFFF0) == 0xFFFFFFF0)

#define GLOBUS_SOAP_MESSAGE_STATUS_ELEMENT_NOT_FOUND   0xFFFFFFF1
#define GLOBUS_SOAP_MESSAGE_STATUS_ATTRIBUTE_NOT_FOUND 0xFFFFFFF2
#define GLOBUS_SOAP_MESSAGE_STATUS_FAILED_ELEMENT      0xFFFFFFF3
#define GLOBUS_SOAP_MESSAGE_STATUS_FAILED_WITH_TEXT    0xFFFFFFF4
#define GLOBUS_SOAP_MESSAGE_STATUS_FAILED_END_ELEMENT  0xFFFFFFF5

#define GlobusSoapMessageStatusElementNotFoundCheck(result)     \
    (GLOBUS_SOAP_MESSAGE_STATUS_ELEMENT_NOT_FOUND == result ||  \
     ((!GlobusSoapMessageStatusReservedResult(result)) &&       \
     (GlobusSoapMessageErrorCheck(result, \
                          GLOBUS_SOAP_MESSAGE_ERROR_TYPE_ELEMENT_NOT_FOUND))))

#define GlobusSoapMessageStatusAttributeNotFoundCheck(result)   \
    (GLOBUS_SOAP_MESSAGE_STATUS_ATTRIBUTE_NOT_FOUND == result ||\
     ((!GlobusSoapMessageStatusReservedResult(result)) &&       \
     (GlobusSoapMessageErrorCheck(result,                       \
                          GLOBUS_SOAP_MESSAGE_ERROR_TYPE_ATTRIBUTE_NOT_FOUND))))

#define GlobusSoapMessageStatusFailedElementCheck(result)       \
    (GLOBUS_SOAP_MESSAGE_STATUS_FAILED_ELEMENT == result ||     \
     ((!GlobusSoapMessageStatusReservedResult(result)) &&       \
     (GlobusSoapMessageErrorCheck(result,                       \
                          GLOBUS_SOAP_MESSAGE_ERROR_TYPE_FAILED_ELEMENT))))


#define GlobusSoapMessageStatusFailedWithTextCheck(result)      \
    (GLOBUS_SOAP_MESSAGE_STATUS_FAILED_WITH_TEXT == result ||   \
     ((!GlobusSoapMessageStatusReservedResult(result)) &&       \
     (GlobusSoapMessageErrorCheck(result,                       \
                          GLOBUS_SOAP_MESSAGE_ERROR_TYPE_FAILED_WITH_TEXT))))

#define GlobusSoapMessageStatusFailedEndElementCheck(result)    \
    (GLOBUS_SOAP_MESSAGE_STATUS_FAILED_END_ELEMENT == result || \
     ((!GlobusSoapMessageStatusReservedResult(result)) &&       \
     (GlobusSoapMessageErrorCheck(result,                       \
                          GLOBUS_SOAP_MESSAGE_ERROR_TYPE_FAILED_END_ELEMENT))))

#define GlobusSoapMessageStatusCheck(result)			\
    (GlobusSoapMessageStatusElementNotFoundCheck(result) ||	\
     GlobusSoapMessageStatusAttributeNotFoundCheck(result) ||	\
     GlobusSoapMessageStatusFailedElementCheck(result) ||	\
     GlobusSoapMessageStatusFailedWithTextCheck(result) ||	\
     GlobusSoapMessageStatusFailedEndElementCheck(result))

#define GlobusSoapMessageErrorCheckFailedResponse(result)       \
    GlobusSoapMessageErrorCheck(                                \
        result,                                                 \
        GLOBUS_SOAP_MESSAGE_ERROR_TYPE_FAILED_RESPONSE)

#define GlobusSoapMessageErrorCheckBadRequest(result)   \
    GlobusSoapMessageErrorCheck(                        \
        result,                                         \
        GLOBUS_SOAP_MESSAGE_ERROR_TYPE_BAD_REQUEST)

#define GlobusSoapMessageErrorCheckFault(result)        \
    GlobusSoapMessageErrorCheck(                        \
        result,                                         \
        GLOBUS_SOAP_MESSAGE_ERROR_TYPE_FAULT)

#define GlobusXSDArrayCheckBounds(__MINOCCURS__,        \
                                  __MAXOCCURS__,        \
                                  __LENGTH__,           \
                                  __ELEMENT__)          \
    ((__LENGTH__ < __MINOCCURS__) ?                     \
     GlobusSoapMessageErrorArrayBelowBounds(            \
         __MINOCCURS__, __LENGTH__, __ELEMENT__) :      \
     ((__LENGTH__ > __MAXOCCURS__) ?                    \
      GlobusSoapMessageErrorArrayAboveBounds(           \
          __MAXOCCURS__, __LENGTH__, __ELEMENT__) :     \
      GLOBUS_SUCCESS))

#define GlobusXSDArrayCheckLowerBounds(__MINOCCURS__,   \
                                       __LENGTH__,      \
                                       __ELEMENT__)     \
    ((__LENGTH__ < __MINOCCURS__) ?                     \
     GlobusSoapMessageErrorArrayBelowBounds(            \
         __MINOCCURS__, __LENGTH__, __ELEMENT__) :      \
     GLOBUS_SUCCESS)

#define GlobusXSDArrayCheckUpperBounds(__MINOCCURS__,   \
                                       __LENGTH__,      \
                                       __ELEMENT__)     \
    ((__LENGTH__ > __MAXOCCURS__) ?                     \
     GlobusSoapMessageErrorArrayAboveBounds(            \
         __MAXOCCURS__, __LENGTH__, __ELEMENT__) :      \
     GLOBUS_SUCCESS)

EXTERN_C_END

#endif
