/*
 * 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_HANDLE_H_
#define _GLOBUS_SOAP_MESSAGE_HANDLE_H_

#include "globus_xio.h"
#include "globus_xio_file_driver.h"
#include "globus_soap_message_attrs.h"

EXTERN_C_BEGIN

#define XSD_NS                    "http://www.w3.org/2001/XMLSchema"
#define XSI_NS                    "http://www.w3.org/2001/XMLSchema-instance"
#define SOAP_ENV_NS               "http://schemas.xmlsoap.org/soap/envelope/"

#define XSD_PREFIX                "xsd"
#define XSI_PREFIX                "xsi"
#define SOAP_ENV_PREFIX           "soapenv"

#define SOAP_ENV                  "Envelope"
#define SOAP_HEADER               "Header"
#define SOAP_BODY                 "Body"

typedef struct globus_soap_message_handle_s * globus_soap_message_handle_t;
typedef void (*globus_destroy_func_t)(void *);

typedef enum
{
    GLOBUS_XSD_ELEMENT_TYPE_ATTR                = 0x01,
    GLOBUS_XSD_ELEMENT_DEFINE_PREFIX            = 0x02,
    GLOBUS_XSD_ELEMENT_SET_DEFAULT_NS           = 0x04,
    GLOBUS_XSD_ELEMENT_CONTENTS_ONLY            = 0x08,
    GLOBUS_XSD_ELEMENT_ATTR_HAS_NULL_NAMESPACE  = 0x10
} globus_xsd_element_options_t;

typedef void (* globus_soap_message_read_callback_func_t) (
    globus_soap_message_handle_t        soap_message,
    globus_result_t                     error,
    void *                              user_args);

typedef void (* globus_soap_message_write_callback_func_t) (
    globus_soap_message_handle_t        soap_message,
    globus_result_t                     error,
    void *                              user_args);

#include "libxml/tree.h"

globus_result_t
globus_soap_message_handle_init_from_dom(
    globus_soap_message_handle_t *      new_handle,
    xmlDocPtr                           dom);

globus_result_t
globus_soap_message_handle_init_from_memory(
    globus_soap_message_handle_t *      new_handle,
    const char *                        buffer,
    int                                 size);

globus_result_t
globus_soap_message_handle_init_from_file(
    globus_soap_message_handle_t *      new_handle,
    const char *                        file_contact);
    
globus_result_t
globus_soap_message_handle_init_to_file(
    globus_soap_message_handle_t *      new_handle,
    const char *                        file_contact,
    globus_xio_file_flag_t              open_flags);

globus_result_t
globus_soap_message_handle_init(
    globus_soap_message_handle_t *      handle,
    globus_xio_handle_t                 xio_handle);

void
globus_soap_message_handle_destroy(
    globus_soap_message_handle_t        handle);

void
globus_soap_message_handle_register_destroy(
    globus_soap_message_handle_t        handle,
    globus_callback_func_t              destroy_callback,
    void *                              destroy_args);

globus_result_t
globus_soap_message_set_marker(
    globus_soap_message_handle_t        handle,
    const char *                        marker);

globus_result_t
globus_soap_message_get_marked_buffer(
    globus_soap_message_handle_t        handle,
    const char *                        marker,
    char **                             buffer,
    size_t *                            buffer_length);

globus_result_t
globus_soap_message_get_marked_buffers(
    globus_soap_message_handle_t        handle,
    const char *                        begin_marker,
    const char *                        end_marker,
    char **                             out_buffer,
    size_t *                            out_length);

globus_result_t
globus_soap_message_replace_marked_buffer(
    globus_soap_message_handle_t             handle,
    const char *                        marker,
    char *                              in_buffer,
    size_t                              in_length);

globus_result_t
globus_soap_message_remove_marked_buffer(
    globus_soap_message_handle_t        handle,
    const char *                        marker);

globus_result_t
globus_soap_message_reset_read_position(
    globus_soap_message_handle_t        handle);

globus_result_t
globus_soap_message_set_read_position_to_marker(
    globus_soap_message_handle_t        handle,
    const char *                        marker);

globus_result_t
globus_soap_message_set_write_position_to_marker(
    globus_soap_message_handle_t        handle,
    const char *                        marker);

globus_result_t
globus_soap_message_handle_set_attrs(
    globus_soap_message_handle_t        handle,
    globus_soap_message_attr_t          attrs);

globus_result_t
globus_soap_message_handle_set_attr(
    globus_soap_message_handle_t             handle,
    const char *                             property_name,
    globus_soap_message_attr_copy_func_t     copy,
    globus_soap_message_attr_destroy_func_t  destroyer,
    void *                                   property);

void *
globus_soap_message_handle_remove_attr(
    globus_soap_message_handle_t        handle,
    const char *                        property_name);

void *
globus_soap_message_handle_get_attr(
    globus_soap_message_handle_t        handle,
    char *                              property_name);

globus_result_t
globus_soap_message_handle_reset(
    globus_soap_message_handle_t             handle);

#include "globus_xsd_type_registry.h"

void
globus_soap_message_handle_get_registry(
    globus_soap_message_handle_t        handle,
    globus_xsd_type_registry_t *        registry);

void
globus_soap_message_handle_set_registry(
    globus_soap_message_handle_t        handle,
    globus_xsd_type_registry_t          registry);

#include "xsd_QName.h"

extern xsd_QName                        soap_env_qname;
extern xsd_QName                        soap_header_qname;
extern xsd_QName                        soap_body_qname;
extern xsd_QName                        soap_mustUnderstand_qname;

typedef globus_result_t (* globus_soap_message_callout_func_t)(
    globus_soap_message_handle_t        message_handle,
    const xsd_QName *                   type);

typedef globus_result_t (* globus_soap_message_callout_ns_func_t)(
    globus_soap_message_handle_t        message_handle,
    const xsd_QName *                   type,
    globus_xsd_element_options_t *      options);

EXTERN_C_END

#endif /* _GLOBUS_SOAP_MESSAGE_HANDLE_H_ */
