/*
 * 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_DELEGATION_CLIENT_UTIL_H_
#define GLOBUS_DELEGATION_CLIENT_UTIL_H_

#include "wsa_EndpointReferenceType.h"
#include "globus_gsi_credential.h"
#include "globus_gsi_cert_utils.h"
#include "globus_common.h"

#define GLOBUS_DELEGATION_CLIENT_UTIL_MODULE \
    &globus_i_delegation_client_util_module
extern globus_module_descriptor_t globus_i_delegation_client_util_module;

typedef struct globus_delegation_client_util_handle_s * 
    globus_delegation_client_util_handle_t;
typedef struct globus_delegation_client_util_attr_s * 
    globus_delegation_client_util_attr_t;

typedef void
(*globus_delegation_client_util_callback_t)(
    globus_delegation_client_util_handle_t handle,
    globus_result_t                     result,
    const wsa_EndpointReferenceType *   delegated_epr,
    void *                              user_arg);

typedef enum
{
    GLOBUS_DELEGATION_CLIENT_UTIL_ERROR_MEMORY,
    GLOBUS_DELEGATION_CLIENT_UTIL_ERROR_INVALID,
    GLOBUS_DELEGATION_CLIENT_UTIL_ERROR_ACTIVE,
    GLOBUS_DELEGATION_CLIENT_UTIL_ERROR_CANCELED,
    GLOBUS_DELEGATION_CLIENT_UTIL_ERROR_WRAPPED,
    GLOBUS_DELEGATION_CLIENT_UTIL_ERROR_WSRF_FAULT,
    GLOBUS_DELEGATION_CLIENT_UTIL_ERROR_PROTOCOL
} globus_delegation_client_util_error_t;

/* no attrs yet, just pass NULL
 * client_handle must outlive this handle
 * 
 *  user_cred can be NULL, in which case the user's default
 *  cred will be used.
 * 
 * currently, message attr must be specified and should include some form
 * of security for delegation to succeed.
 * 
 * handler chain can be null
 */
globus_result_t
globus_delegation_client_util_handle_init(
    globus_delegation_client_util_handle_t * handle,
    globus_soap_message_attr_t               message_attr,
    globus_handler_chain_t                   handler_chain,
    const globus_gsi_cred_handle_t           user_cred,
    globus_delegation_client_util_attr_t     attr);

void
globus_delegation_client_util_handle_destroy(
    globus_delegation_client_util_handle_t handle);

globus_result_t
globus_delegation_client_util_cancel(
    globus_delegation_client_util_handle_t handle);

/**
 *  proxy_type should normally be one of 
 *   GLOBUS_GSI_CERT_UTILS_TYPE_GSI_3_IMPERSONATION_PROXY (full) and
 *   GLOBUS_GSI_CERT_UTILS_TYPE_GSI_3_LIMITED_PROXY (limited)
 */
globus_result_t
globus_delegation_client_util_delegate_epr_register(
    globus_delegation_client_util_handle_t handle,
    const wsa_EndpointReferenceType *   delegate_factory_epr,
    globus_gsi_cert_utils_cert_type_t   proxy_type,
    globus_delegation_client_util_callback_t callback,
    void *                              user_arg);

globus_result_t
globus_delegation_client_util_delegate_register(
    globus_delegation_client_util_handle_t handle,
    const char *                        delegate_factory,
    globus_gsi_cert_utils_cert_type_t   proxy_type,
    globus_delegation_client_util_callback_t callback,
    void *                              user_arg);

globus_result_t
globus_delegation_client_util_delegate_epr(
    globus_delegation_client_util_handle_t handle,
    const wsa_EndpointReferenceType *   delegate_factory_epr,
    globus_gsi_cert_utils_cert_type_t   proxy_type,
    wsa_EndpointReferenceType **        delegated_epr);

globus_result_t
globus_delegation_client_util_delegate(
    globus_delegation_client_util_handle_t handle,
    const char *                        delegate_factory,
    globus_gsi_cert_utils_cert_type_t   proxy_type,
    wsa_EndpointReferenceType **        delegated_epr);

#endif
