Loading...
Searching...
No Matches
globus_i_xio_http.h
/*
* Copyright 1999-2006 University of Chicago
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef GLOBUS_DONT_DOCUMENT_INTERNAL
#ifndef GLOBUS_I_XIO_HTTP_H
#define GLOBUS_I_XIO_HTTP_H 1
#include "globus_xio.h"
#include "globus_xio_driver.h"
#include "globus_xio_http.h"
enum { GLOBUS_XIO_HTTP_CHUNK_SIZE = 4000 };
typedef enum
{
GLOBUS_XIO_HTTP_TRANSFER_ENCODING_DEFAULT,
GLOBUS_XIO_HTTP_TRANSFER_ENCODING_IDENTITY,
GLOBUS_XIO_HTTP_TRANSFER_ENCODING_CHUNKED
}
globus_i_xio_http_transfer_encoding_t;
typedef enum
{
GLOBUS_XIO_HTTP_PRE_REQUEST_LINE,
GLOBUS_XIO_HTTP_REQUEST_LINE,
GLOBUS_XIO_HTTP_STATUS_LINE,
GLOBUS_XIO_HTTP_HEADERS,
GLOBUS_XIO_HTTP_CHUNK_CRLF,
GLOBUS_XIO_HTTP_CHUNK_LINE,
GLOBUS_XIO_HTTP_CHUNK_FOOTERS,
GLOBUS_XIO_HTTP_CHUNK_BODY,
GLOBUS_XIO_HTTP_IDENTITY_BODY,
GLOBUS_XIO_HTTP_EOF,
GLOBUS_XIO_HTTP_CLOSE
}
globus_i_xio_http_parse_state_t;
typedef struct
{
struct globus_i_xio_http_handle_s * http_handle;
globus_xio_operation_t user_read_op;
globus_xio_operation_t internal_op;
globus_xio_driver_handle_t driver_handle;
}
globus_i_xio_http_cancellation_t;
#define GLOBUS_XIO_HTTP_COPY_BLOB(fifo, blob, len, label) \
do { \
result = globus_i_xio_http_copy_blob(fifo, blob, len); \
if (result != GLOBUS_SUCCESS) \
{ \
goto label; \
} \
} while (0);
typedef struct
{
globus_xio_iovec_t * iov;
globus_size_t iovcnt;
globus_xio_operation_t operation;
globus_xio_driver_handle_t driver_handle;
globus_size_t nbytes;
int wait_for;
globus_byte_t chunk_size_buffer[64];
}
globus_i_xio_http_operation_info_t;
#define GLOBUS_XIO_ARRAY_LENGTH(x) (sizeof(x)/sizeof(x[0]))
#if BUILD_DEBUG
#define GLOBUS_XIO_HTTP_TODO(msg) \
do { \
globus_libc_fprintf(stderr, "TODO: %s\n", msg); \
} while (0);
#else
#define GLOBUS_XIO_HTTP_TODO(msg) \
do { \
globus_libc_fprintf(stderr, "TODO: %s\n", msg); \
abort(); \
} while (0);
#endif
typedef struct
{
globus_bool_t is_client;
char * host;
unsigned short port;
char * uri;
}
globus_i_xio_http_target_t;
typedef enum
{
GLOBUS_I_XIO_HTTP_HEADER_ENTITY_NEEDED = 1 << 0,
GLOBUS_I_XIO_HTTP_HEADER_CONTENT_LENGTH_SET = 1 << 1,
GLOBUS_I_XIO_HTTP_HEADER_CONNECTION_CLOSE = 1 << 2
}
globus_i_xio_http_header_flags_t;
#define GLOBUS_I_XIO_HTTP_HEADER_IS_ENTITY_NEEDED(header) \
((header)->flags & GLOBUS_I_XIO_HTTP_HEADER_ENTITY_NEEDED)
#define GLOBUS_I_XIO_HTTP_HEADER_IS_CONTENT_LENGTH_SET(header) \
((header)->flags & GLOBUS_I_XIO_HTTP_HEADER_CONTENT_LENGTH_SET)
#define GLOBUS_I_XIO_HTTP_HEADER_IS_CONNECTION_CLOSE(header) \
((header)->flags & GLOBUS_I_XIO_HTTP_HEADER_CONNECTION_CLOSE)
typedef struct
{
globus_hashtable_t headers;
globus_off_t content_length;
globus_i_xio_http_transfer_encoding_t
transfer_encoding;
globus_i_xio_http_header_flags_t flags;
}
globus_i_xio_http_header_info_t;
typedef struct
{
char * uri;
char * method;
globus_xio_http_version_t http_version;
globus_i_xio_http_header_info_t headers;
}
globus_i_xio_http_request_t;
typedef struct
{
int status_code;
char * reason_phrase;
globus_xio_http_version_t http_version;
globus_i_xio_http_header_info_t headers;
}
globus_i_xio_http_response_t;
typedef struct globus_i_xio_http_handle_s
{
globus_i_xio_http_target_t target_info;
globus_i_xio_http_request_t request_info;
globus_i_xio_http_response_t response_info;
globus_xio_driver_handle_t handle;
globus_xio_iovec_t * header_iovec;
int header_iovcnt;
globus_xio_iovec_t read_buffer;
globus_xio_iovec_t read_iovec;
globus_size_t read_buffer_offset;
globus_size_t read_buffer_valid;
globus_xio_operation_t close_operation;
globus_size_t read_chunk_left;
globus_bool_t delay_write_header;
const globus_xio_iovec_t * first_write_iovec;
int first_write_iovec_count;
globus_i_xio_http_parse_state_t parse_state;
globus_i_xio_http_parse_state_t send_state;
globus_xio_operation_t response_read_operation;
globus_i_xio_http_operation_info_t read_operation;
globus_i_xio_http_operation_info_t write_operation;
globus_bool_t user_close;
globus_bool_t read_response;
globus_mutex_t mutex;
globus_i_xio_http_cancellation_t * cancellation;
globus_bool_t reopen_in_progress;
/* error from internal response read, usually with a broken persistent
* connection
*/
globus_object_t * pending_error;
}
globus_i_xio_http_handle_t;
typedef struct
{
/* attrs for client side */
globus_i_xio_http_request_t request;
globus_bool_t delay_write_header;
/* only one attr for server side for now*/
globus_i_xio_http_response_t response;
}
globus_i_xio_http_attr_t;
/* globus_xio_http.c */
extern
globus_result_t
globus_i_xio_http_copy_blob(
globus_fifo_t * fifo,
const char * blob,
size_t len);
extern
char *
globus_i_xio_http_find_eol(
char * blob,
globus_size_t blob_length);
extern
globus_bool_t
globus_i_xio_http_method_requires_entity(
const char * method);
extern
globus_xio_http_version_t
globus_i_xio_http_guess_version(
int major_version,
int minor_version);
extern
globus_result_t
globus_i_xio_http_clean_read_buffer(
globus_i_xio_http_handle_t * http_handle);
/* globus_xio_http_attr.c */
extern
globus_result_t
globus_i_xio_http_attr_init(
void ** out_attr);
extern
globus_result_t
globus_i_xio_http_attr_cntl(
void * driver_attr,
int cmd,
va_list ap);
extern
globus_result_t
globus_i_xio_http_attr_copy(
void ** dst,
void * src);
extern
globus_result_t
globus_i_xio_http_attr_destroy(
void * driver_attr);
/* globus_xio_http_client.c */
extern
globus_result_t
globus_i_xio_http_client_write_request(
globus_xio_operation_t op,
globus_i_xio_http_handle_t * http_handle);
extern
void
globus_i_xio_http_client_open_callback(
globus_xio_operation_t op,
globus_result_t result,
void * user_arg);
/* globus_xio_http_handle.c */
extern
globus_result_t
globus_i_xio_http_handle_init(
globus_i_xio_http_handle_t * http_handle,
globus_i_xio_http_attr_t * attr,
globus_i_xio_http_target_t * target);
extern
globus_result_t
globus_i_xio_http_handle_reinit(
globus_i_xio_http_handle_t * http_handle,
globus_i_xio_http_attr_t * http_attr,
globus_i_xio_http_target_t * http_target);
extern
void
globus_i_xio_http_handle_destroy(
globus_i_xio_http_handle_t * http_handle);
extern
globus_result_t
globus_i_xio_http_handle_cntl(
void * handle,
int cmd,
va_list ap);
extern
globus_result_t
globus_i_xio_http_set_end_of_entity(
globus_i_xio_http_handle_t * http_handle);
/* globus_xio_http_header.c */
extern
void
globus_i_xio_http_header_copy(
void ** dest_key,
void ** dest_datum,
void * src_key,
void * src_datum);
extern
void
globus_i_xio_http_header_destroy(
void * header);
extern
globus_result_t
globus_i_xio_http_header_parse(
globus_i_xio_http_handle_t * handle,
globus_bool_t * done);
/* globus_xio_http_header_info.c */
extern
globus_result_t
globus_i_xio_http_header_info_init(
globus_i_xio_http_header_info_t * headers);
extern
void
globus_i_xio_http_header_info_destroy(
globus_i_xio_http_header_info_t * headers);
extern
globus_result_t
globus_i_xio_http_header_info_copy(
globus_i_xio_http_header_info_t * dest,
const globus_i_xio_http_header_info_t *
src);
extern
globus_result_t
globus_i_xio_http_header_info_set_header(
globus_i_xio_http_header_info_t * headers,
const char * header_name,
const char * header_value,
globus_bool_t store_all);
/* globus_xio_http_rfc2616.c */
extern
const char *
globus_i_xio_http_lookup_reason(
int code);
/* globus_xio_http_target.c */
extern
globus_i_xio_http_target_t *
globus_i_xio_http_target_new(void);
extern
globus_result_t
globus_i_xio_http_target_destroy(
void * driver_target);
extern
void
globus_i_xio_http_target_destroy_internal(
globus_i_xio_http_target_t * target);
/* globus_xio_http_request_t */
extern
globus_result_t
globus_i_xio_http_request_init(
globus_i_xio_http_request_t * request);
extern
globus_result_t
globus_i_xio_http_request_copy(
globus_i_xio_http_request_t * dest,
const globus_i_xio_http_request_t * src);
extern
void
globus_i_xio_http_request_destroy(
globus_i_xio_http_request_t * request);
/* globus_xio_http_response.c */
extern
globus_result_t
globus_i_xio_http_response_init(
globus_i_xio_http_response_t * response);
extern
globus_result_t
globus_i_xio_http_response_copy(
globus_i_xio_http_response_t * dest,
const globus_i_xio_http_response_t *src);
extern
void
globus_i_xio_http_response_destroy(
globus_i_xio_http_response_t * response);
/* globus_xio_http_server.c */
extern
void
globus_i_xio_http_server_read_request_callback(
globus_xio_operation_t op,
globus_result_t result,
globus_size_t nbytes,
void * user_arg);
extern
globus_result_t
globus_i_xio_http_accept(
void * driver_server,
globus_xio_operation_t accept_op);
extern
void
globus_i_xio_http_server_open_callback(
globus_xio_operation_t op,
globus_result_t result,
void * user_arg);
extern
globus_result_t
globus_i_xio_http_server_write_response(
globus_i_xio_http_handle_t * http_handle,
const globus_xio_iovec_t * iovec,
int iovec_count,
globus_xio_operation_t op);
extern
globus_result_t
globus_i_xio_http_server_read_next_request(
globus_i_xio_http_handle_t * http_handle);
/* globus_xio_http_target.c */
extern
globus_result_t
globus_i_xio_http_target_init(
globus_i_xio_http_target_t ** out_target,
const globus_xio_contact_t * contact_info);
extern
globus_result_t
globus_i_xio_http_target_copy(
globus_i_xio_http_target_t * dest,
const globus_i_xio_http_target_t * src);
/* globus_xio_http_transform.c */
extern globus_list_t * globus_i_xio_http_cached_handles;
extern globus_mutex_t globus_i_xio_http_cached_handle_mutex;
extern globus_list_t * globus_i_xio_http_cancellable_handles;
extern globus_mutex_t globus_i_xio_http_cancel_mutex;
extern
globus_result_t
globus_i_xio_http_open(
const globus_xio_contact_t * contact_info,
void * link,
void * attr,
globus_xio_operation_t op);
extern
globus_result_t
globus_i_xio_http_read(
void * handle,
const globus_xio_iovec_t * iovec,
int iovec_count,
globus_xio_operation_t op);
extern
globus_result_t
globus_i_xio_http_write(
void * handle,
const globus_xio_iovec_t * iovec,
int iovec_count,
globus_xio_operation_t op);
extern
globus_result_t
globus_l_xio_http_client_parse_response(
globus_i_xio_http_handle_t * http_handle,
globus_bool_t * done);
void
globus_l_xio_http_client_read_response_callback(
globus_xio_operation_t op,
globus_result_t result,
globus_size_t nbytes,
void * user_arg);
extern
globus_result_t
globus_i_xio_http_parse_residue(
globus_i_xio_http_handle_t * handle,
globus_bool_t * registered_again);
extern
globus_result_t
globus_i_xio_http_write_chunk(
globus_i_xio_http_handle_t * http_handle,
const globus_xio_iovec_t * iovec,
int iovec_count,
globus_xio_operation_t op);
extern
void
globus_i_xio_http_write_callback(
globus_xio_operation_t op,
globus_result_t result,
globus_size_t nbytes,
void * user_arg);
extern
globus_result_t
globus_i_xio_http_close(
void * handle,
void * attr,
globus_xio_operation_t op);
extern
globus_result_t
globus_i_xio_http_close_internal(
globus_i_xio_http_handle_t * http_handle);
extern
void
globus_i_xio_http_close_callback(
globus_xio_operation_t operation,
globus_result_t result,
void * handle);
GlobusXIODeclareModule(http);
#define GLOBUS_XIO_HTTP_MODULE GlobusXIOMyModule(http)
#define GlobusXIOHttpErrorObjParse(token, context) \
globus_error_construct_error( \
GLOBUS_XIO_HTTP_MODULE, \
GLOBUS_NULL, \
GLOBUS_XIO_HTTP_ERROR_PARSE, \
__FILE__, \
_xio_name, \
__LINE__, \
"Error parsing %s token at %s", \
token, context)
#define GlobusXIOHttpErrorParse(token, context) \
globus_error_put( \
GlobusXIOHttpErrorObjParse(token, context))
#define GlobusXIOHttpErrorObjInvalidHeader(name, value) \
globus_error_construct_error( \
GLOBUS_XIO_HTTP_MODULE, \
GLOBUS_NULL, \
GLOBUS_XIO_HTTP_ERROR_INVALID_HEADER, \
__FILE__, \
_xio_name, \
__LINE__, \
"Invalid %s header value %s", \
name, value)
#define GlobusXIOHttpErrorInvalidHeader(name, value) \
globus_error_put( \
GlobusXIOHttpErrorObjInvalidHeader(name, value))
#define GlobusXIOHttpErrorObjNoEntity() \
globus_error_construct_error( \
GLOBUS_XIO_HTTP_MODULE, \
GLOBUS_NULL, \
GLOBUS_XIO_HTTP_ERROR_NO_ENTITY, \
__FILE__, \
_xio_name, \
__LINE__, \
"No entity to read or write")
#define GlobusXIOHttpErrorNoEntity() \
globus_error_put( \
GlobusXIOHttpErrorObjNoEntity())
#define GlobusXIOHttpErrorObjEOF() \
globus_error_construct_error( \
GLOBUS_XIO_HTTP_MODULE, \
GLOBUS_NULL, \
GLOBUS_XIO_HTTP_ERROR_EOF, \
__FILE__, \
_xio_name, \
__LINE__, \
"End of Entity")
#define GlobusXIOHttpErrorEOF() \
globus_error_put( \
GlobusXIOHttpErrorObjEOF())
#define GlobusXIOHttpErrorPersistentConnectionDropped(cause) \
globus_error_put( \
GlobusXIOHTTPErrorObjPersistentConnectionDropped(cause))
#define GlobusXIOHTTPErrorObjPersistentConnectionDropped(cause) \
globus_error_construct_error( \
GLOBUS_XIO_HTTP_MODULE, \
cause, \
GLOBUS_XIO_HTTP_ERROR_PERSISTENT_CONNECTION_DROPPED, \
__FILE__, \
_xio_name, \
__LINE__, \
"Persistent connection dropped")
#endif /* GLOBUS_I_XIO_HTTP_H */
#endif /* GLOBUS_DONT_DOCUMENT_INTERNAL */
globus_xio_http.h
Globus XIO HTTP Driver Header.
globus_xio_http_version_t
globus_xio_http_version_t
Definition globus_xio_http.h:232