summaryrefslogtreecommitdiffstats
path: root/guththila
diff options
context:
space:
mode:
Diffstat (limited to 'guththila')
-rw-r--r--guththila/include/guththila_reader.h25
-rw-r--r--guththila/src/guththila_reader.c72
2 files changed, 68 insertions, 29 deletions
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,