From e58fa35ea4989a309b9b392ec97c09ddc9dc54d8 Mon Sep 17 00:00:00 2001 From: shankar Date: Tue, 23 Mar 2010 05:56:22 +0000 Subject: refactoring git-svn-id: http://svn.apache.org/repos/asf/axis/axis2/c/core/trunk@926468 13f79535-47bb-0310-9956-ffa450edef68 --- guththila/src/guththila_reader.c | 72 +++++++++++++++++++++++++++++----------- 1 file changed, 53 insertions(+), 19 deletions(-) (limited to 'guththila/src/guththila_reader.c') 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 #include #include + 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, -- cgit v1.1-32-gdbae