/*
 * 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_FAULT_H_
#define _GLOBUS_SOAP_MESSAGE_FAULT_H_

#include "xsd_any.h"

#define SOAP_FAULT                "Fault"
#define SOAP_FAULTCODE            "faultcode"
#define SOAP_FAULTACTOR           "faultactor"
#define SOAP_FAULTSTRING          "faultstring"
#define SOAP_FAULT_DETAIL         "detail"

extern xsd_QName                        soap_fault_qname;
extern xsd_QName                        soap_faultcode_qname;
extern xsd_QName                        soap_faultactor_qname;
extern xsd_QName                        soap_faultstring_qname;
extern xsd_QName                        soap_fault_detail_qname;

typedef struct globus_soap_message_fault_s
{
    char *                              faultcode;
    char *                              faultstring;
    char *                              faultactor;
    xsd_any *                           detail;
} * globus_soap_message_fault_t;

globus_result_t
globus_soap_message_fault_init(
    globus_soap_message_fault_t *       fault);

void
globus_soap_message_fault_destroy(
    void *                              fault);

#include "globus_soap_message_handle.h"

extern globus_object_type_t       globus_l_soap_fault_type;
#define GLOBUS_SOAP_FAULT_TYPE          &globus_l_soap_fault_type

globus_soap_message_fault_t
globus_soap_message_fault_get(
    globus_object_t *                   obj);

globus_bool_t
globus_soap_message_is_fault(
    globus_object_t *                   obj);

globus_object_t *
globus_soap_message_fault_object_initialize(
    globus_soap_message_fault_t         fault);

#define GLOBUS_SOAP_MESSAGE_ERROR_FAULT_OBJECT(                         \
    soap_fault)                                                         \
        globus_error_construct_error(                                   \
            GLOBUS_SOAP_MESSAGE_MODULE,                                 \
            globus_soap_message_fault_object_initialize(soap_fault),    \
            GLOBUS_SOAP_MESSAGE_ERROR_TYPE_FAULT,                       \
            __FILE__,                                                   \
            _globus_func_name,                                          \
            __LINE__,                                                   \
            "SOAP Fault")

#define GlobusSoapMessageErrorFault(                    \
    soap_fault)                                         \
        globus_error_put(                               \
            GLOBUS_SOAP_MESSAGE_ERROR_FAULT_OBJECT(     \
                soap_fault))

typedef void (* globus_soap_fault_callback_func_t) (
    globus_soap_message_handle_t        handle,
    const xsd_QName *                   fault_qname,
    int *                               fault_type,
    void *                              user_args);

globus_result_t
globus_soap_message_deserialize_fault(
    globus_soap_message_handle_t        handle,
    globus_soap_message_fault_t *       soap_fault_handle,
    globus_soap_fault_callback_func_t   fault_callback,
    xsd_any **                          fault_any,
    void *                              user_data);

/**
 * globus_result_t
 * globus_soap_message_deserialize_fault_end(
 *     globus_soap_message_handle_t             handle);
 */
#define globus_soap_message_deserialize_fault_end(HANDLE, QNAME) \
    globus_soap_message_deserialize_element_end(HANDLE, QNAME)

globus_result_t
globus_soap_message_serialize_fault(
    globus_soap_message_handle_t        handle,
    globus_soap_message_fault_t         fault);

#endif
