diff options
-rw-r--r-- | axiom/src/parser/guththila/guththila_xml_reader_wrapper.c | 306 | ||||
-rw-r--r-- | guththila/include/guththila_reader.h | 25 | ||||
-rw-r--r-- | guththila/src/guththila_reader.c | 72 |
3 files changed, 170 insertions, 233 deletions
diff --git a/axiom/src/parser/guththila/guththila_xml_reader_wrapper.c b/axiom/src/parser/guththila/guththila_xml_reader_wrapper.c index 086ed12..6dfce12 100644 --- a/axiom/src/parser/guththila/guththila_xml_reader_wrapper.c +++ b/axiom/src/parser/guththila/guththila_xml_reader_wrapper.c @@ -22,15 +22,18 @@ /**************** function prototypes ******************************************/ -int AXIS2_CALL guththila_xml_reader_wrapper_next( +int AXIS2_CALL +guththila_xml_reader_wrapper_next( axiom_xml_reader_t * parser, const axutil_env_t * env); -void AXIS2_CALL guththila_xml_reader_wrapper_free( +void AXIS2_CALL +guththila_xml_reader_wrapper_free( axiom_xml_reader_t * parser, const axutil_env_t * env); -int AXIS2_CALL guththila_xml_reader_wrapper_get_attribute_count( +int AXIS2_CALL +guththila_xml_reader_wrapper_get_attribute_count( axiom_xml_reader_t * parser, const axutil_env_t * env); @@ -58,11 +61,13 @@ guththila_xml_reader_wrapper_get_attribute_namespace_by_number( const axutil_env_t * env, int i); -axis2_char_t *AXIS2_CALL guththila_xml_reader_wrapper_get_value( +axis2_char_t *AXIS2_CALL +guththila_xml_reader_wrapper_get_value( axiom_xml_reader_t * parser, const axutil_env_t * env); -int AXIS2_CALL guththila_xml_reader_wrapper_get_namespace_count( +int AXIS2_CALL +guththila_xml_reader_wrapper_get_namespace_count( axiom_xml_reader_t * parser, const axutil_env_t * env); @@ -78,36 +83,44 @@ guththila_xml_reader_wrapper_get_namespace_prefix_by_number( const axutil_env_t * env, int i); -axis2_char_t *AXIS2_CALL guththila_xml_reader_wrapper_get_prefix( +axis2_char_t *AXIS2_CALL +guththila_xml_reader_wrapper_get_prefix( axiom_xml_reader_t * parser, const axutil_env_t * env); -axis2_char_t *AXIS2_CALL guththila_xml_reader_wrapper_get_name( +axis2_char_t *AXIS2_CALL +guththila_xml_reader_wrapper_get_name( axiom_xml_reader_t * parser, const axutil_env_t * env); -axis2_char_t *AXIS2_CALL guththila_xml_reader_wrapper_get_pi_target( +axis2_char_t *AXIS2_CALL +guththila_xml_reader_wrapper_get_pi_target( axiom_xml_reader_t * parser, const axutil_env_t * env); -axis2_char_t *AXIS2_CALL guththila_xml_reader_wrapper_get_pi_data( +axis2_char_t *AXIS2_CALL +guththila_xml_reader_wrapper_get_pi_data( axiom_xml_reader_t * parser, const axutil_env_t * env); -axis2_char_t *AXIS2_CALL guththila_xml_reader_wrapper_get_dtd( +axis2_char_t *AXIS2_CALL +guththila_xml_reader_wrapper_get_dtd( axiom_xml_reader_t * parser, const axutil_env_t * env); -void AXIS2_CALL guththila_xml_reader_wrapper_xml_free( +void AXIS2_CALL +guththila_xml_reader_wrapper_xml_free( axiom_xml_reader_t * parser, const axutil_env_t * env, void *data); -axis2_char_t *AXIS2_CALL guththila_xml_reader_wrapper_get_char_set_encoding( +axis2_char_t *AXIS2_CALL +guththila_xml_reader_wrapper_get_char_set_encoding( axiom_xml_reader_t * parser, const axutil_env_t * env); -axis2_char_t *AXIS2_CALL guththila_xml_reader_wrapper_get_namespace_uri( +axis2_char_t *AXIS2_CALL +guththila_xml_reader_wrapper_get_namespace_uri( axiom_xml_reader_t * parser, const axutil_env_t * env); @@ -147,37 +160,38 @@ typedef struct guththila_xml_reader_wrapper_impl /**********End macros -- event_map initializing function *********************/ -static axis2_status_t +static void guththila_xml_reader_wrapper_init_map( guththila_xml_reader_wrapper_impl_t * parser) { - if(parser) - { - parser->event_map[GUTHTHILA_START_DOCUMENT] = AXIOM_XML_READER_START_DOCUMENT; - parser->event_map[GUTHTHILA_START_ELEMENT] = AXIOM_XML_READER_START_ELEMENT; - parser->event_map[GUTHTHILA_END_ELEMENT] = AXIOM_XML_READER_END_ELEMENT; - parser->event_map[GUTHTHILA_SPACE] = AXIOM_XML_READER_SPACE; - parser->event_map[GUTHTHILA_EMPTY_ELEMENT] = AXIOM_XML_READER_EMPTY_ELEMENT; - parser->event_map[GUTHTHILA_CHARACTER] = AXIOM_XML_READER_CHARACTER; - parser->event_map[GUTHTHILA_ENTITY_REFERANCE] = AXIOM_XML_READER_ENTITY_REFERENCE; - parser->event_map[GUTHTHILA_COMMENT] = AXIOM_XML_READER_COMMENT; - return AXIS2_SUCCESS; - } - return AXIS2_FAILURE; + parser->event_map[GUTHTHILA_START_DOCUMENT] = AXIOM_XML_READER_START_DOCUMENT; + parser->event_map[GUTHTHILA_START_ELEMENT] = AXIOM_XML_READER_START_ELEMENT; + parser->event_map[GUTHTHILA_END_ELEMENT] = AXIOM_XML_READER_END_ELEMENT; + parser->event_map[GUTHTHILA_SPACE] = AXIOM_XML_READER_SPACE; + parser->event_map[GUTHTHILA_EMPTY_ELEMENT] = AXIOM_XML_READER_EMPTY_ELEMENT; + parser->event_map[GUTHTHILA_CHARACTER] = AXIOM_XML_READER_CHARACTER; + parser->event_map[GUTHTHILA_ENTITY_REFERANCE] = AXIOM_XML_READER_ENTITY_REFERENCE; + parser->event_map[GUTHTHILA_COMMENT] = AXIOM_XML_READER_COMMENT; } -static const axiom_xml_reader_ops_t axiom_xml_reader_ops_var = { guththila_xml_reader_wrapper_next, - guththila_xml_reader_wrapper_free, guththila_xml_reader_wrapper_get_attribute_count, +static const axiom_xml_reader_ops_t axiom_xml_reader_ops_var = { + guththila_xml_reader_wrapper_next, + guththila_xml_reader_wrapper_free, + guththila_xml_reader_wrapper_get_attribute_count, guththila_xml_reader_wrapper_get_attribute_name_by_number, guththila_xml_reader_wrapper_get_attribute_prefix_by_number, guththila_xml_reader_wrapper_get_attribute_value_by_number, guththila_xml_reader_wrapper_get_attribute_namespace_by_number, - guththila_xml_reader_wrapper_get_value, guththila_xml_reader_wrapper_get_namespace_count, + guththila_xml_reader_wrapper_get_value, + guththila_xml_reader_wrapper_get_namespace_count, guththila_xml_reader_wrapper_get_namespace_uri_by_number, guththila_xml_reader_wrapper_get_namespace_prefix_by_number, - guththila_xml_reader_wrapper_get_prefix, guththila_xml_reader_wrapper_get_name, - guththila_xml_reader_wrapper_get_pi_target, guththila_xml_reader_wrapper_get_pi_data, - guththila_xml_reader_wrapper_get_dtd, guththila_xml_reader_wrapper_xml_free, + guththila_xml_reader_wrapper_get_prefix, + guththila_xml_reader_wrapper_get_name, + guththila_xml_reader_wrapper_get_pi_target, + guththila_xml_reader_wrapper_get_pi_data, + guththila_xml_reader_wrapper_get_dtd, + guththila_xml_reader_wrapper_xml_free, guththila_xml_reader_wrapper_get_char_set_encoding, guththila_xml_reader_wrapper_get_namespace_uri, guththila_xml_reader_wrapper_get_namespace_uri_by_prefix, @@ -186,65 +200,67 @@ static const axiom_xml_reader_ops_t axiom_xml_reader_ops_var = { guththila_xml_r /********************************************************************************/ -AXIS2_EXTERN axiom_xml_reader_t *AXIS2_CALL -axiom_xml_reader_create_for_file( - const axutil_env_t * env, - char *filename, - const axis2_char_t * encoding) +static axiom_xml_reader_t *AXIS2_CALL +axiom_xml_reader_create_basic( + const axutil_env_t *env, + guththila_reader_t *reader, + void *ctx) { guththila_xml_reader_wrapper_impl_t *guththila_impl = NULL; guththila_t *guththila = NULL; - AXIS2_ENV_CHECK(env, NULL); + if(!reader) + { + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Invalid guththila reader"); + return NULL; + } guththila_impl = AXIS2_MALLOC(env->allocator, sizeof(guththila_xml_reader_wrapper_impl_t)); - if(!guththila_impl) { AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE); + guththila_reader_free(reader, env); + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Insufficient memory to create xml reader wrapper"); return NULL; } - guththila_impl->reader = guththila_reader_create_for_file(filename, env); - - if(!(guththila_impl->reader)) + guththila = (guththila_t *)AXIS2_MALLOC(env->allocator, sizeof(guththila_t)); + if(!guththila) { AXIS2_FREE(env->allocator, guththila_impl); + guththila_reader_free(reader, env); AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE); + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Insufficient memory to create guththila"); return NULL; } - guththila = (guththila_t *)AXIS2_MALLOC(env->allocator, sizeof(guththila_t)); - guththila_init(guththila, guththila_impl->reader, env); - if(!guththila) + if(guththila_init(guththila, reader, env) != GUTHTHILA_SUCCESS) { AXIS2_FREE(env->allocator, guththila_impl); - AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE); + AXIS2_FREE(env->allocator, guththila); + guththila_reader_free(reader, env); + AXIS2_ERROR_SET(env->error, AXIS2_ERROR_CREATING_XML_STREAM_READER, AXIS2_FAILURE); + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Guththila initialization failed"); return NULL; } guththila_impl->guththila_parser = guththila; - guththila_impl->context = NULL; - guththila_impl->parser.ops = NULL; - /* guththila_impl->parser.ops = - (axiom_xml_reader_ops_t *) AXIS2_MALLOC(env->allocator, - sizeof(axiom_xml_reader_ops_t)); - if (!(guththila_impl->parser.ops)) - { - guththila_free(guththila, env); - AXIS2_FREE(env->allocator, guththila_impl); - AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE); - return NULL; - } - */ + guththila_impl->reader = reader; + guththila_impl->context = ctx; guththila_xml_reader_wrapper_init_map(guththila_impl); - - /************** ops *****/ guththila_impl->parser.ops = &axiom_xml_reader_ops_var; return &(guththila_impl->parser); } -/****** pull parser for io create function ***************************/ +AXIS2_EXTERN axiom_xml_reader_t *AXIS2_CALL +axiom_xml_reader_create_for_file( + const axutil_env_t * env, + char *filename, + const axis2_char_t * encoding) +{ + guththila_reader_t *reader = guththila_reader_create_for_file(filename, env); + return axiom_xml_reader_create_basic(env, reader, NULL); +} axiom_xml_reader_t *AXIS2_CALL axiom_xml_reader_create_for_io( @@ -254,62 +270,22 @@ axiom_xml_reader_create_for_io( void *ctx, const char *encoding) { - guththila_xml_reader_wrapper_impl_t *guththila_impl = NULL; - /*axutil_allocator_t *allocator = NULL; */ - guththila_t *guththila = NULL; - - AXIS2_ENV_CHECK(env, NULL); - - guththila_impl = AXIS2_MALLOC(env->allocator, sizeof(guththila_xml_reader_wrapper_impl_t)); - - if(!guththila_impl) - { - AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE); - return NULL; - } - - /*allocator = axutil_allocator_init(NULL); */ - - /*-------difference of two create function is here--------*/ - guththila_impl->reader = guththila_reader_create_for_io(read_input_callback, ctx, env); - - if(!(guththila_impl->reader)) - { - AXIS2_FREE(env->allocator, guththila_impl); - AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE); - return NULL; - } - - guththila = (guththila_t *)AXIS2_MALLOC(env->allocator, sizeof(guththila_t)); - guththila_init(guththila, guththila_impl->reader, env); - if(!guththila) - { - AXIS2_FREE(env->allocator, guththila_impl); - AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE); - return NULL; - } - - guththila_impl->guththila_parser = guththila; - guththila_impl->context = ctx; - guththila_impl->parser.ops = NULL; - /* guththila_impl->parser.ops = (axiom_xml_reader_ops_t *) - AXIS2_MALLOC(env->allocator, sizeof(axiom_xml_reader_ops_t)); - if (!(guththila_impl->parser.ops)) - { - guththila_free(guththila, env); - AXIS2_FREE(env->allocator, guththila_impl); - AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE); - return NULL; - }*/ - - guththila_xml_reader_wrapper_init_map(guththila_impl); + guththila_reader_t *reader = guththila_reader_create_for_io(read_input_callback, ctx, env); + return axiom_xml_reader_create_basic(env, reader, ctx); +} - /************** ops *****/ - guththila_impl->parser.ops = &axiom_xml_reader_ops_var; - return &(guththila_impl->parser); +AXIS2_EXTERN axiom_xml_reader_t *AXIS2_CALL +axiom_xml_reader_create_for_memory( + const axutil_env_t * env, + void *buffer, + int size, + const char *encoding, + int type) +{ + guththila_reader_t *reader = guththila_reader_create_for_memory(buffer, size, env); + return axiom_xml_reader_create_basic(env, reader, NULL); } -/* ####################################################################### */ AXIS2_EXTERN axis2_status_t AXIS2_CALL axiom_xml_reader_init() { @@ -322,78 +298,12 @@ axiom_xml_reader_cleanup() return AXIS2_SUCCESS; } -/* ######################################################################## */ - -AXIS2_EXTERN axiom_xml_reader_t *AXIS2_CALL -axiom_xml_reader_create_for_memory( - const axutil_env_t * env, - void *buffer, - int size, - const char *encoding, - int type) -{ - guththila_xml_reader_wrapper_impl_t *guththila_impl = NULL; - /*axutil_allocator_t *allocator = NULL; */ - guththila_t *guththila = NULL; - - AXIS2_ENV_CHECK(env, NULL); - - guththila_impl = AXIS2_MALLOC(env->allocator, sizeof(guththila_xml_reader_wrapper_impl_t)); - - if(!guththila_impl) - { - AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE); - return NULL; - } - - /*allocator = axutil_allocator_init(NULL); */ - - /*-------difference of two create function is here--------*/ - guththila_impl->reader = guththila_reader_create_for_memory(buffer, size, env); - - if(!(guththila_impl->reader)) - { - AXIS2_FREE(env->allocator, guththila_impl); - AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE); - return NULL; - } - - guththila = (guththila_t *)AXIS2_MALLOC(env->allocator, sizeof(guththila_t)); - guththila_init(guththila, guththila_impl->reader, env); - if(!guththila) - { - AXIS2_FREE(env->allocator, guththila_impl); - AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE); - return NULL; - } - - guththila_impl->guththila_parser = guththila; - guththila_impl->context = NULL; - guththila_impl->parser.ops = NULL; - /* guththila_impl->parser.ops = (axiom_xml_reader_ops_t *) - AXIS2_MALLOC(env->allocator, sizeof(axiom_xml_reader_ops_t)); - if (!(guththila_impl->parser.ops)) - { - guththila_free(guththila, env); - AXIS2_FREE(env->allocator, guththila_impl); - AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE); - return NULL; - } - */ - guththila_xml_reader_wrapper_init_map(guththila_impl); - - /************** ops *****/ - guththila_impl->parser.ops = &axiom_xml_reader_ops_var; - return &(guththila_impl->parser); -} - int AXIS2_CALL guththila_xml_reader_wrapper_next( axiom_xml_reader_t * parser, const axutil_env_t * env) { int i = -1; - AXIS2_ENV_CHECK(env, -1); i = guththila_next(AXIS2_INTF_TO_IMPL(parser)->guththila_parser, env); return i == -1 ? -1 : AXIS2_INTF_TO_IMPL(parser)->event_map[i]; } @@ -404,7 +314,6 @@ guththila_xml_reader_wrapper_free( const axutil_env_t * env) { guththila_xml_reader_wrapper_impl_t *parser_impl = NULL; - AXIS2_ENV_CHECK(env, AXIS2_FAILURE); parser_impl = AXIS2_INTF_TO_IMPL(parser); if(parser_impl->reader) { @@ -424,7 +333,6 @@ guththila_xml_reader_wrapper_get_attribute_count( axiom_xml_reader_t * parser, const axutil_env_t * env) { - AXIS2_ENV_CHECK(env, AXIS2_FAILURE); return guththila_get_attribute_count(AXIS2_INTF_TO_IMPL(parser)-> guththila_parser, env); } @@ -434,9 +342,8 @@ guththila_xml_reader_wrapper_get_attribute_name_by_number( const axutil_env_t * env, int i) { - AXIS2_ENV_CHECK(env, NULL); - return guththila_get_attribute_name_by_number(AXIS2_INTF_TO_IMPL(parser)-> guththila_parser, i, - env); + return guththila_get_attribute_name_by_number( + AXIS2_INTF_TO_IMPL(parser)-> guththila_parser, i, env); } axis2_char_t *AXIS2_CALL @@ -445,9 +352,8 @@ guththila_xml_reader_wrapper_get_attribute_prefix_by_number( const axutil_env_t * env, int i) { - AXIS2_ENV_CHECK(env, NULL); - return guththila_get_attribute_prefix_by_number(AXIS2_INTF_TO_IMPL(parser)-> guththila_parser, - i, env); + return guththila_get_attribute_prefix_by_number( + AXIS2_INTF_TO_IMPL(parser)-> guththila_parser, i, env); } axis2_char_t *AXIS2_CALL @@ -456,9 +362,8 @@ guththila_xml_reader_wrapper_get_attribute_value_by_number( const axutil_env_t * env, int i) { - AXIS2_ENV_CHECK(env, NULL); - return guththila_get_attribute_value_by_number(AXIS2_INTF_TO_IMPL(parser)-> guththila_parser, - i, env); + return guththila_get_attribute_value_by_number( + AXIS2_INTF_TO_IMPL(parser)-> guththila_parser, i, env); } axis2_char_t *AXIS2_CALL @@ -467,7 +372,6 @@ guththila_xml_reader_wrapper_get_attribute_namespace_by_number( const axutil_env_t * env, int i) { - AXIS2_ENV_CHECK(env, NULL); return guththila_get_attribute_namespace_by_number( AXIS2_INTF_TO_IMPL(parser)-> guththila_parser, i, env); } @@ -477,7 +381,6 @@ guththila_xml_reader_wrapper_get_value( axiom_xml_reader_t * parser, const axutil_env_t * env) { - AXIS2_ENV_CHECK(env, NULL); return guththila_get_value(AXIS2_INTF_TO_IMPL(parser)->guththila_parser, env); } @@ -486,7 +389,6 @@ guththila_xml_reader_wrapper_get_namespace_count( axiom_xml_reader_t * parser, const axutil_env_t * env) { - AXIS2_ENV_CHECK(env, AXIS2_FAILURE); return guththila_get_namespace_count(AXIS2_INTF_TO_IMPL(parser)-> guththila_parser, env); } @@ -496,9 +398,8 @@ guththila_xml_reader_wrapper_get_namespace_uri_by_number( const axutil_env_t * env, int i) { - AXIS2_ENV_CHECK(env, NULL); - return guththila_get_namespace_uri_by_number(AXIS2_INTF_TO_IMPL(parser)-> guththila_parser, i, - env); + return guththila_get_namespace_uri_by_number( + AXIS2_INTF_TO_IMPL(parser)-> guththila_parser, i, env); } axis2_char_t *AXIS2_CALL @@ -507,9 +408,8 @@ guththila_xml_reader_wrapper_get_namespace_prefix_by_number( const axutil_env_t * env, int i) { - AXIS2_ENV_CHECK(env, NULL); - return guththila_get_namespace_prefix_by_number(AXIS2_INTF_TO_IMPL(parser)-> guththila_parser, - i, env); + return guththila_get_namespace_prefix_by_number( + AXIS2_INTF_TO_IMPL(parser)-> guththila_parser, i, env); } axis2_char_t *AXIS2_CALL @@ -517,7 +417,6 @@ guththila_xml_reader_wrapper_get_prefix( axiom_xml_reader_t * parser, const axutil_env_t * env) { - AXIS2_ENV_CHECK(env, NULL); return guththila_get_prefix(AXIS2_INTF_TO_IMPL(parser)->guththila_parser, env); } @@ -526,7 +425,6 @@ guththila_xml_reader_wrapper_get_name( axiom_xml_reader_t * parser, const axutil_env_t * env) { - AXIS2_ENV_CHECK(env, NULL); return guththila_get_name(AXIS2_INTF_TO_IMPL(parser)->guththila_parser, env); } diff --git a/guththila/include/guththila_reader.h b/guththila/include/guththila_reader.h index cad53a1..657153b 100644 --- a/guththila/include/guththila_reader.h +++ b/guththila/include/guththila_reader.h @@ -60,8 +60,9 @@ typedef struct guththila_reader_s * @param env environment */ GUTHTHILA_EXPORT guththila_reader_t * GUTHTHILA_CALL -guththila_reader_create_for_file(guththila_char_t *filename, - const axutil_env_t * env); +guththila_reader_create_for_file( + guththila_char_t *filename, + const axutil_env_t * env); /* * Reading from a call back function. @@ -70,9 +71,10 @@ guththila_reader_create_for_file(guththila_char_t *filename, * @param env environment */ GUTHTHILA_EXPORT guththila_reader_t * GUTHTHILA_CALL -guththila_reader_create_for_io(GUTHTHILA_READ_INPUT_CALLBACK - input_read_callback, void *ctx, - const axutil_env_t * env); +guththila_reader_create_for_io( + GUTHTHILA_READ_INPUT_CALLBACK input_read_callback, + void *ctx, + const axutil_env_t * env); /* * Reading from memory buffer. @@ -81,9 +83,10 @@ guththila_reader_create_for_io(GUTHTHILA_READ_INPUT_CALLBACK * @param env environment */ GUTHTHILA_EXPORT guththila_reader_t * GUTHTHILA_CALL -guththila_reader_create_for_memory(void *buffer, - int size, - const axutil_env_t * env); +guththila_reader_create_for_memory( + void *buffer, + int size, + const axutil_env_t * env); /* * Read the specified number of character to the given buffer. @@ -94,7 +97,8 @@ guththila_reader_create_for_memory(void *buffer, * @param env environment * @return number of bytes put in to the buffer. -1 if end of the read. */ -GUTHTHILA_EXPORT int GUTHTHILA_CALL guththila_reader_read( +GUTHTHILA_EXPORT int GUTHTHILA_CALL +guththila_reader_read( guththila_reader_t * r, guththila_char_t * buffer, int offset, @@ -106,7 +110,8 @@ GUTHTHILA_EXPORT int GUTHTHILA_CALL guththila_reader_read( * @param r reader * @param env environment */ -GUTHTHILA_EXPORT void GUTHTHILA_CALL guththila_reader_free( +GUTHTHILA_EXPORT void GUTHTHILA_CALL +guththila_reader_free( guththila_reader_t * r, const axutil_env_t * env); diff --git a/guththila/src/guththila_reader.c b/guththila/src/guththila_reader.c index bcb0efd..8c15d9a 100644 --- a/guththila/src/guththila_reader.c +++ b/guththila/src/guththila_reader.c @@ -17,27 +17,46 @@ #include <stdlib.h> #include <string.h> #include <guththila_reader.h> + GUTHTHILA_EXPORT guththila_reader_t * GUTHTHILA_CALL guththila_reader_create_for_file( guththila_char_t *file_name, const axutil_env_t * env) { - guththila_reader_t * reader = NULL; - + guththila_reader_t * reader; FILE * f = NULL; + if(!file_name) + { + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "[guththila] invalid file name"); + AXIS2_ERROR_SET(env->error, AXIS2_ERROR_COULD_NOT_OPEN_FILE, AXIS2_FAILURE); return NULL; + } + reader = (guththila_reader_t *)AXIS2_MALLOC(env->allocator, sizeof(guththila_reader_t)); if(!reader) + { + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, + "[guththila]insufficient memory to create guththila parser"); + AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE); return NULL; + } + f = fopen(file_name, "r"); if(!f) { AXIS2_FREE(env->allocator, reader); + AXIS2_ERROR_SET(env->error, AXIS2_ERROR_COULD_NOT_OPEN_FILE, AXIS2_FAILURE); + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "[guththila] unable to open file %s", file_name); return NULL; } + reader->fp = f; reader->type = GUTHTHILA_FILE_READER; + reader->buff = NULL; + reader->buff_size = 0; + reader->input_read_callback = NULL; + reader->context = NULL; return reader; } @@ -47,17 +66,23 @@ guththila_reader_create_for_memory( int size, const axutil_env_t * env) { - guththila_reader_t * reader = (guththila_reader_t *)AXIS2_MALLOC(env->allocator, - sizeof(guththila_reader_t)); - if(reader) + guththila_reader_t * reader; + reader = (guththila_reader_t *)AXIS2_MALLOC(env->allocator, sizeof(guththila_reader_t)); + if(!reader) { - reader->type = GUTHTHILA_MEMORY_READER; - reader->buff = buffer; - reader->buff_size = size; - reader->fp = NULL; - return reader; + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, + "[guththila]insufficient memory to create guththila parser"); + AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE); + return NULL; } - return NULL; + + reader->type = GUTHTHILA_MEMORY_READER; + reader->buff = buffer; + reader->buff_size = size; + reader->fp = NULL; + reader->input_read_callback = NULL; + reader->context = NULL; + return reader; } GUTHTHILA_EXPORT guththila_reader_t * GUTHTHILA_CALL @@ -66,17 +91,25 @@ guththila_reader_create_for_io( void *ctx, const axutil_env_t * env) { - guththila_reader_t * reader = (guththila_reader_t *)AXIS2_MALLOC(env->allocator, - sizeof(guththila_reader_t)); - if(reader) + guththila_reader_t * reader; + reader = (guththila_reader_t *)AXIS2_MALLOC(env->allocator, sizeof(guththila_reader_t)); + if(!reader) { - reader->input_read_callback = input_read_callback; - reader->context = ctx; - reader->type = GUTHTHILA_IO_READER; - return reader; + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, + "[guththila]insufficient memory to create guththila parser"); + AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE); + return NULL; } - return NULL; + + reader->input_read_callback = input_read_callback; + reader->context = ctx; + reader->type = GUTHTHILA_IO_READER; + reader->buff = NULL; + reader->buff_size = 0; + reader->fp = NULL; + return reader; } + GUTHTHILA_EXPORT void GUTHTHILA_CALL guththila_reader_free( guththila_reader_t * r, @@ -93,6 +126,7 @@ guththila_reader_free( AXIS2_FREE(env->allocator, r); } + GUTHTHILA_EXPORT int GUTHTHILA_CALL guththila_reader_read( guththila_reader_t * r, |