diff options
Diffstat (limited to 'axiom/src/parser')
-rw-r--r-- | axiom/src/parser/Makefile.am | 3 | ||||
-rw-r--r-- | axiom/src/parser/guththila/Makefile.am | 13 | ||||
-rw-r--r-- | axiom/src/parser/guththila/guththila_xml_reader_wrapper.c | 613 | ||||
-rw-r--r-- | axiom/src/parser/guththila/guththila_xml_writer_wrapper.c | 787 | ||||
-rw-r--r-- | axiom/src/parser/libxml2/Makefile.am | 17 | ||||
-rw-r--r-- | axiom/src/parser/libxml2/libxml2_reader_wrapper.c | 949 | ||||
-rw-r--r-- | axiom/src/parser/libxml2/libxml2_writer_wrapper.c | 1571 | ||||
-rw-r--r-- | axiom/src/parser/xml_reader.c | 203 | ||||
-rw-r--r-- | axiom/src/parser/xml_writer.c | 337 |
9 files changed, 4493 insertions, 0 deletions
diff --git a/axiom/src/parser/Makefile.am b/axiom/src/parser/Makefile.am new file mode 100644 index 0000000..6c1d2ba --- /dev/null +++ b/axiom/src/parser/Makefile.am @@ -0,0 +1,3 @@ +SUBDIRS = $(WRAPPER_DIR) + +DIST_SUBDIRS=guththila libxml2 diff --git a/axiom/src/parser/guththila/Makefile.am b/axiom/src/parser/guththila/Makefile.am new file mode 100644 index 0000000..0cc6be5 --- /dev/null +++ b/axiom/src/parser/guththila/Makefile.am @@ -0,0 +1,13 @@ +lib_LTLIBRARIES = libaxis2_parser.la + +libaxis2_parser_la_LIBADD = ../../../../guththila/src/libguththila.la \ + ../../../../util/src/libaxutil.la + +libaxis2_parser_la_SOURCES = ../xml_reader.c ../xml_writer.c guththila_xml_writer_wrapper.c \ + guththila_xml_reader_wrapper.c + +libaxis2_parser_la_LDFLAGS = -version-info $(VERSION_NO) + +INCLUDES = -I$(top_builddir)/include \ + -I ../../../../util/include \ + -I ../../../../guththila/include diff --git a/axiom/src/parser/guththila/guththila_xml_reader_wrapper.c b/axiom/src/parser/guththila/guththila_xml_reader_wrapper.c new file mode 100644 index 0000000..086ed12 --- /dev/null +++ b/axiom/src/parser/guththila/guththila_xml_reader_wrapper.c @@ -0,0 +1,613 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + */ + +#include <axiom_xml_reader.h> +#include <axutil_env.h> +#include <axutil_utils.h> +#include <guththila.h> + +/**************** function prototypes ******************************************/ + +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( + axiom_xml_reader_t * parser, + const axutil_env_t * env); + +int AXIS2_CALL guththila_xml_reader_wrapper_get_attribute_count( + axiom_xml_reader_t * parser, + const axutil_env_t * env); + +axis2_char_t *AXIS2_CALL +guththila_xml_reader_wrapper_get_attribute_name_by_number( + axiom_xml_reader_t * parser, + const axutil_env_t * env, + int i); + +axis2_char_t *AXIS2_CALL +guththila_xml_reader_wrapper_get_attribute_prefix_by_number( + axiom_xml_reader_t * parser, + const axutil_env_t * env, + int i); + +axis2_char_t *AXIS2_CALL +guththila_xml_reader_wrapper_get_attribute_value_by_number( + axiom_xml_reader_t * parser, + const axutil_env_t * env, + int i); + +axis2_char_t *AXIS2_CALL +guththila_xml_reader_wrapper_get_attribute_namespace_by_number( + axiom_xml_reader_t * parser, + const axutil_env_t * env, + int i); + +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( + axiom_xml_reader_t * parser, + const axutil_env_t * env); + +axis2_char_t *AXIS2_CALL +guththila_xml_reader_wrapper_get_namespace_uri_by_number( + axiom_xml_reader_t * parser, + const axutil_env_t * env, + int i); + +axis2_char_t *AXIS2_CALL +guththila_xml_reader_wrapper_get_namespace_prefix_by_number( + axiom_xml_reader_t * parser, + const axutil_env_t * env, + int i); + +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( + axiom_xml_reader_t * parser, + const axutil_env_t * env); + +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( + axiom_xml_reader_t * parser, + const axutil_env_t * env); + +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( + 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( + axiom_xml_reader_t * parser, + const axutil_env_t * env); + +axis2_char_t *AXIS2_CALL guththila_xml_reader_wrapper_get_namespace_uri( + axiom_xml_reader_t * parser, + const axutil_env_t * env); + +axis2_char_t *AXIS2_CALL +guththila_xml_reader_wrapper_get_namespace_uri_by_prefix( + axiom_xml_reader_t * parser, + const axutil_env_t * env, + axis2_char_t * prefix); + +void *AXIS2_CALL +guththila_xml_reader_wrapper_get_context( + axiom_xml_reader_t * parser, + const axutil_env_t * env); + +axis2_char_t *AXIS2_CALL +guththila_xml_reader_wrapper_get_current_buffer( + axiom_xml_reader_t * parser, + const axutil_env_t * env); + +/*********** guththila_xml_reader_wrapper_impl_t wrapper struct *******************/ + +typedef struct guththila_xml_reader_wrapper_impl +{ + axiom_xml_reader_t parser; + guththila_t *guththila_parser; + guththila_reader_t *reader; + int event_map[10]; + void *context; + +} guththila_xml_reader_wrapper_impl_t; + +/********************************* Macro ***************************************/ + +#define AXIS2_INTF_TO_IMPL(p) ((guththila_xml_reader_wrapper_impl_t*)p) + +#define AXIS2_IMPL_TO_INTF(p) &(p->parser) + +/**********End macros -- event_map initializing function *********************/ + +static axis2_status_t +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; +} + +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_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_char_set_encoding, + guththila_xml_reader_wrapper_get_namespace_uri, + guththila_xml_reader_wrapper_get_namespace_uri_by_prefix, + guththila_xml_reader_wrapper_get_context, + guththila_xml_reader_wrapper_get_current_buffer}; + +/********************************************************************************/ + +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_xml_reader_wrapper_impl_t *guththila_impl = 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; + } + + guththila_impl->reader = guththila_reader_create_for_file(filename, 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); +} + +/****** pull parser for io create function ***************************/ + +axiom_xml_reader_t *AXIS2_CALL +axiom_xml_reader_create_for_io( + const axutil_env_t * env, + AXIS2_READ_INPUT_CALLBACK read_input_callback, + AXIS2_CLOSE_INPUT_CALLBACK close_input_callback, + 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); + + /************** ops *****/ + guththila_impl->parser.ops = &axiom_xml_reader_ops_var; + return &(guththila_impl->parser); +} + +/* ####################################################################### */ +AXIS2_EXTERN axis2_status_t AXIS2_CALL +axiom_xml_reader_init() +{ + return AXIS2_SUCCESS; +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +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]; +} + +void AXIS2_CALL +guththila_xml_reader_wrapper_free( + axiom_xml_reader_t * parser, + 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) + { + guththila_reader_free(parser_impl->reader, env); + } + + if(parser_impl->guththila_parser) + { + guththila_un_init(parser_impl->guththila_parser, env); + } + + AXIS2_FREE(env->allocator, parser_impl); +} + +int AXIS2_CALL +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); +} + +axis2_char_t *AXIS2_CALL +guththila_xml_reader_wrapper_get_attribute_name_by_number( + axiom_xml_reader_t * parser, + 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); +} + +axis2_char_t *AXIS2_CALL +guththila_xml_reader_wrapper_get_attribute_prefix_by_number( + axiom_xml_reader_t * parser, + 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); +} + +axis2_char_t *AXIS2_CALL +guththila_xml_reader_wrapper_get_attribute_value_by_number( + axiom_xml_reader_t * parser, + 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); +} + +axis2_char_t *AXIS2_CALL +guththila_xml_reader_wrapper_get_attribute_namespace_by_number( + axiom_xml_reader_t * parser, + 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); +} + +axis2_char_t *AXIS2_CALL +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); +} + +int AXIS2_CALL +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); +} + +axis2_char_t *AXIS2_CALL +guththila_xml_reader_wrapper_get_namespace_uri_by_number( + axiom_xml_reader_t * parser, + 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); +} + +axis2_char_t *AXIS2_CALL +guththila_xml_reader_wrapper_get_namespace_prefix_by_number( + axiom_xml_reader_t * parser, + 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); +} + +axis2_char_t *AXIS2_CALL +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); +} + +axis2_char_t *AXIS2_CALL +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); +} + +axis2_char_t *AXIS2_CALL +guththila_xml_reader_wrapper_get_pi_target( + axiom_xml_reader_t * parser, + const axutil_env_t * env) +{ + /* guththila_does not support pi's yet */ + return NULL; +} + +axis2_char_t *AXIS2_CALL +guththila_xml_reader_wrapper_get_pi_data( + axiom_xml_reader_t * parser, + const axutil_env_t * env) +{ + /* guththila_dose not support yet */ + return NULL; +} + +axis2_char_t *AXIS2_CALL +guththila_xml_reader_wrapper_get_dtd( + axiom_xml_reader_t * parser, + const axutil_env_t * env) +{ + printf("not implemented in guththila"); + return NULL; +} + +void AXIS2_CALL +guththila_xml_reader_wrapper_xml_free( + axiom_xml_reader_t * parser, + const axutil_env_t * env, + void *data) +{ + if(data) + AXIS2_FREE(env->allocator, data); +} + +axis2_char_t *AXIS2_CALL +guththila_xml_reader_wrapper_get_char_set_encoding( + axiom_xml_reader_t * parser, + const axutil_env_t * env) +{ + return guththila_get_encoding(AXIS2_INTF_TO_IMPL(parser)->guththila_parser, env); +} + +axis2_char_t *AXIS2_CALL +guththila_xml_reader_wrapper_get_namespace_uri( + axiom_xml_reader_t * parser, + const axutil_env_t * env) +{ + + return (axis2_char_t *)NULL; +} + +axis2_char_t *AXIS2_CALL +guththila_xml_reader_wrapper_get_namespace_uri_by_prefix( + axiom_xml_reader_t * parser, + const axutil_env_t * env, + axis2_char_t * prefix) +{ + return (axis2_char_t *)NULL; +} + +void *AXIS2_CALL +guththila_xml_reader_wrapper_get_context( + axiom_xml_reader_t * parser, + const axutil_env_t * env) +{ + guththila_xml_reader_wrapper_impl_t* parser_impl = NULL; + parser_impl = AXIS2_INTF_TO_IMPL(parser); + return parser_impl->context; +} + +axis2_char_t *AXIS2_CALL +guththila_xml_reader_wrapper_get_current_buffer( + axiom_xml_reader_t * parser, + const axutil_env_t * env) +{ + return guththila_get_current_buffer(AXIS2_INTF_TO_IMPL(parser)->guththila_parser, env); +} + diff --git a/axiom/src/parser/guththila/guththila_xml_writer_wrapper.c b/axiom/src/parser/guththila/guththila_xml_writer_wrapper.c new file mode 100644 index 0000000..31b4040 --- /dev/null +++ b/axiom/src/parser/guththila/guththila_xml_writer_wrapper.c @@ -0,0 +1,787 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + */ + +#include <guththila_xml_writer.h> +#include <axutil_utils.h> +#include <axutil_env.h> +#include <axiom_xml_writer.h> +#include <string.h> + +/************************ function prototypes ************************************/ +void AXIS2_CALL guththila_xml_writer_wrapper_free( + axiom_xml_writer_t * writer, + const axutil_env_t * env); + +axis2_status_t AXIS2_CALL +guththila_xml_writer_wrapper_write_start_element( + axiom_xml_writer_t * writer, + const axutil_env_t * env, + axis2_char_t * localname); + +axis2_status_t AXIS2_CALL +guththila_xml_writer_wrapper_end_start_element( + axiom_xml_writer_t * writer, + const axutil_env_t * env); + +axis2_status_t AXIS2_CALL +guththila_xml_writer_wrapper_write_start_element_with_namespace( + axiom_xml_writer_t * writer, + const axutil_env_t * env, + axis2_char_t * localname, + axis2_char_t * namespace_uri); + +axis2_status_t AXIS2_CALL +guththila_xml_writer_wrapper_write_start_element_with_namespace_prefix( + axiom_xml_writer_t * writer, + const axutil_env_t * env, + axis2_char_t * localname, + axis2_char_t * namespace_uri, + axis2_char_t * prefix); + +axis2_status_t AXIS2_CALL +guththila_xml_writer_wrapper_write_empty_element( + axiom_xml_writer_t * writer, + const axutil_env_t * env, + axis2_char_t * localname); + +axis2_status_t AXIS2_CALL +guththila_xml_writer_wrapper_write_empty_element_with_namespace( + axiom_xml_writer_t * writer, + const axutil_env_t * env, + axis2_char_t * localname, + axis2_char_t * namespace_uri); + +axis2_status_t AXIS2_CALL +guththila_xml_writer_wrapper_write_empty_element_with_namespace_prefix( + axiom_xml_writer_t * writer, + const axutil_env_t * env, + axis2_char_t * localname, + axis2_char_t * namespace_uri, + axis2_char_t * prefix); + +axis2_status_t AXIS2_CALL +guththila_xml_writer_wrapper_write_end_element( + axiom_xml_writer_t * writer, + const axutil_env_t * env); + +axis2_status_t AXIS2_CALL +guththila_xml_writer_wrapper_write_end_document( + axiom_xml_writer_t * writer, + const axutil_env_t * env); + +axis2_status_t AXIS2_CALL +guththila_xml_writer_wrapper_write_attribute( + axiom_xml_writer_t * writer, + const axutil_env_t * env, + axis2_char_t * localname, + axis2_char_t * value); + +axis2_status_t AXIS2_CALL +guththila_xml_writer_wrapper_write_attribute_with_namespace( + axiom_xml_writer_t * writer, + const axutil_env_t * env, + axis2_char_t * localname, + axis2_char_t * value, + axis2_char_t * namespace_uri); + +axis2_status_t AXIS2_CALL +guththila_xml_writer_wrapper_write_attribute_with_namespace_prefix( + axiom_xml_writer_t * writer, + const axutil_env_t * env, + axis2_char_t * localname, + axis2_char_t * value, + axis2_char_t * namespace_uri, + axis2_char_t * prefix); + +axis2_status_t AXIS2_CALL +guththila_xml_writer_wrapper_write_namespace( + axiom_xml_writer_t * writer, + const axutil_env_t * env, + axis2_char_t * prefix, + axis2_char_t * namespace_uri); + +axis2_status_t AXIS2_CALL +guththila_xml_writer_wrapper_write_default_namespace( + axiom_xml_writer_t * writer, + const axutil_env_t * env, + axis2_char_t * namespace_uri); + +axis2_status_t AXIS2_CALL +guththila_xml_writer_wrapper_write_comment( + axiom_xml_writer_t * writer, + const axutil_env_t * env, + axis2_char_t * value); + +axis2_status_t AXIS2_CALL +guththila_xml_writer_wrapper_write_processing_instruction( + axiom_xml_writer_t * writer, + const axutil_env_t * env, + axis2_char_t * target); + +axis2_status_t AXIS2_CALL +guththila_xml_writer_wrapper_write_processing_instruction_data( + axiom_xml_writer_t * writer, + const axutil_env_t * env, + axis2_char_t * target, + axis2_char_t * data); + +axis2_status_t AXIS2_CALL +guththila_xml_writer_wrapper_write_cdata( + axiom_xml_writer_t * writer, + const axutil_env_t * env, + axis2_char_t * data); + +axis2_status_t AXIS2_CALL +guththila_xml_writer_wrapper_write_dtd( + axiom_xml_writer_t * writer, + const axutil_env_t * env, + axis2_char_t * dtd); + +axis2_status_t AXIS2_CALL +guththila_xml_writer_wrapper_write_entity_ref( + axiom_xml_writer_t * writer, + const axutil_env_t * env, + axis2_char_t * name); + +axis2_status_t AXIS2_CALL +guththila_xml_writer_wrapper_write_start_document( + axiom_xml_writer_t * writer, + const axutil_env_t * env); + +axis2_status_t AXIS2_CALL +guththila_xml_writer_wrapper_write_start_document_with_version( + axiom_xml_writer_t * writer, + const axutil_env_t * env, + axis2_char_t * version); + +axis2_status_t AXIS2_CALL +guththila_xml_writer_wrapper_write_start_document_with_version_encoding( + axiom_xml_writer_t * writer, + const axutil_env_t * env, + axis2_char_t * encoding, + axis2_char_t * version); + +axis2_status_t AXIS2_CALL +guththila_xml_writer_wrapper_write_characters( + axiom_xml_writer_t * writer, + const axutil_env_t * env, + axis2_char_t * text); + +axis2_char_t *AXIS2_CALL guththila_xml_writer_wrapper_get_prefix( + axiom_xml_writer_t * writer, + const axutil_env_t * env, + axis2_char_t * uri); + +axis2_status_t AXIS2_CALL +guththila_xml_writer_wrapper_set_prefix( + axiom_xml_writer_t * writer, + const axutil_env_t * env, + axis2_char_t * prefix, + axis2_char_t * uri); + +axis2_status_t AXIS2_CALL +guththila_xml_writer_wrapper_set_default_prefix( + axiom_xml_writer_t * writer, + const axutil_env_t * env, + axis2_char_t * uri); + +axis2_status_t AXIS2_CALL +guththila_xml_writer_wrapper_write_encoded( + axiom_xml_writer_t * writer, + const axutil_env_t * env, + axis2_char_t * text, + int in_attr); + +void *AXIS2_CALL guththila_xml_writer_wrapper_get_xml( + axiom_xml_writer_t * writer, + const axutil_env_t * env); + +unsigned int AXIS2_CALL guththila_xml_writer_wrapper_get_xml_size( + axiom_xml_writer_t * writer, + const axutil_env_t * env); + +int AXIS2_CALL guththila_xml_writer_wrapper_get_type( + axiom_xml_writer_t * writer, + const axutil_env_t * env); + +axis2_status_t AXIS2_CALL +guththila_xml_writer_wrapper_write_raw( + axiom_xml_writer_t * writer, + const axutil_env_t * env, + axis2_char_t * content); + +axis2_status_t AXIS2_CALL +guththila_xml_writer_wrapper_flush( + axiom_xml_writer_t * writer, + const axutil_env_t * env); + +/***************************** end function pointers *****************************/ + +typedef struct guththila_xml_writer_wrapper_impl +{ + axiom_xml_writer_t writer; + guththila_xml_writer_t *wr; +} guththila_xml_writer_wrapper_impl_t; + +static const axiom_xml_writer_ops_t axiom_xml_writer_ops_var = { guththila_xml_writer_wrapper_free, + guththila_xml_writer_wrapper_write_start_element, + guththila_xml_writer_wrapper_end_start_element, + guththila_xml_writer_wrapper_write_start_element_with_namespace, + guththila_xml_writer_wrapper_write_start_element_with_namespace_prefix, + guththila_xml_writer_wrapper_write_empty_element, + guththila_xml_writer_wrapper_write_empty_element_with_namespace, + guththila_xml_writer_wrapper_write_empty_element_with_namespace_prefix, + guththila_xml_writer_wrapper_write_end_element, + guththila_xml_writer_wrapper_write_end_document, guththila_xml_writer_wrapper_write_attribute, + guththila_xml_writer_wrapper_write_attribute_with_namespace, + guththila_xml_writer_wrapper_write_attribute_with_namespace_prefix, + guththila_xml_writer_wrapper_write_namespace, + guththila_xml_writer_wrapper_write_default_namespace, + guththila_xml_writer_wrapper_write_comment, + guththila_xml_writer_wrapper_write_processing_instruction, + guththila_xml_writer_wrapper_write_processing_instruction_data, + guththila_xml_writer_wrapper_write_cdata, guththila_xml_writer_wrapper_write_dtd, + guththila_xml_writer_wrapper_write_entity_ref, + guththila_xml_writer_wrapper_write_start_document, + guththila_xml_writer_wrapper_write_start_document_with_version, + guththila_xml_writer_wrapper_write_start_document_with_version_encoding, + guththila_xml_writer_wrapper_write_characters, guththila_xml_writer_wrapper_get_prefix, + guththila_xml_writer_wrapper_set_prefix, guththila_xml_writer_wrapper_set_default_prefix, + guththila_xml_writer_wrapper_write_encoded, guththila_xml_writer_wrapper_get_xml, + guththila_xml_writer_wrapper_get_xml_size, guththila_xml_writer_wrapper_get_type, + guththila_xml_writer_wrapper_write_raw, guththila_xml_writer_wrapper_flush }; + +/****************************** Macros *******************************************/ + +#define AXIS2_INTF_TO_IMPL(p) ((guththila_xml_writer_wrapper_impl_t*)p) + +/******************************* End macro ***************************************/ + +AXIS2_EXTERN axiom_xml_writer_t *AXIS2_CALL +axiom_xml_writer_create( + const axutil_env_t * env, + axis2_char_t * filename, + axis2_char_t * encoding, + int is_prefix_default, + int compression) +{ + guththila_xml_writer_wrapper_impl_t *writer_impl; + + AXIS2_ENV_CHECK(env, NULL); + + writer_impl = (guththila_xml_writer_wrapper_impl_t *)AXIS2_MALLOC(env->allocator, + sizeof(guththila_xml_writer_wrapper_impl_t)); + return &(writer_impl->writer); +} + +AXIS2_EXTERN axiom_xml_writer_t *AXIS2_CALL +axiom_xml_writer_create_for_memory( + const axutil_env_t * env, + axis2_char_t * encoding, + int is_prefix_default, + int compression, + int type) +{ + guththila_xml_writer_wrapper_impl_t *writer_impl = NULL; + + AXIS2_ENV_CHECK(env, NULL); + + writer_impl = (guththila_xml_writer_wrapper_impl_t *)AXIS2_MALLOC(env->allocator, + sizeof(guththila_xml_writer_wrapper_impl_t)); + + if(!writer_impl) + { + AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE); + return NULL; + } + + /* creating guththila parser */ + /* guththila xml stream writer for memory */ + + writer_impl->wr = guththila_create_xml_stream_writer_for_memory(env); + + if(!(writer_impl->wr)) + { + AXIS2_FREE(env->allocator, writer_impl->wr); + AXIS2_FREE(env->allocator, writer_impl); + AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE); + return NULL; + } + + writer_impl->writer.ops = NULL; + /* ops */ + writer_impl->writer.ops = &axiom_xml_writer_ops_var; + return &(writer_impl->writer); + +} + +void AXIS2_CALL +guththila_xml_writer_wrapper_free( + axiom_xml_writer_t * writer, + const axutil_env_t * env) +{ + AXIS2_ENV_CHECK(env, AXIS2_FAILURE); + if(AXIS2_INTF_TO_IMPL(writer)->wr) + { + guththila_xml_writer_free(AXIS2_INTF_TO_IMPL(writer)->wr, env); + } + + if(writer) + { + AXIS2_FREE(env->allocator, AXIS2_INTF_TO_IMPL(writer)); + } + +} + +axis2_status_t AXIS2_CALL +guththila_xml_writer_wrapper_write_start_element( + axiom_xml_writer_t * writer, + const axutil_env_t * env, + axis2_char_t * localname) +{ + int status = AXIS2_SUCCESS; + AXIS2_ENV_CHECK(env, AXIS2_FAILURE); + AXIS2_PARAM_CHECK(env->error, localname, AXIS2_FAILURE); + guththila_write_start_element(AXIS2_INTF_TO_IMPL(writer)->wr, localname, env); + return status; +} + +axis2_status_t AXIS2_CALL +guththila_xml_writer_wrapper_write_start_element_with_namespace( + axiom_xml_writer_t * writer, + const axutil_env_t * env, + axis2_char_t * localname, + axis2_char_t * namespace_uri) +{ + int status = AXIS2_SUCCESS; + AXIS2_ENV_CHECK(env, AXIS2_FAILURE); + AXIS2_PARAM_CHECK(env->error, localname, AXIS2_FAILURE); + AXIS2_PARAM_CHECK(env->error, namespace_uri, AXIS2_FAILURE); + guththila_write_start_element_with_namespace(AXIS2_INTF_TO_IMPL(writer)->wr, namespace_uri, + localname, env); + return status; +} + +axis2_status_t AXIS2_CALL +guththila_xml_writer_wrapper_write_start_element_with_namespace_prefix( + axiom_xml_writer_t * writer, + const axutil_env_t * env, + axis2_char_t * localname, + axis2_char_t * namespace_uri, + axis2_char_t * prefix) +{ + AXIS2_ENV_CHECK(env, AXIS2_FAILURE); + AXIS2_PARAM_CHECK(env->error, localname, AXIS2_FAILURE); + AXIS2_PARAM_CHECK(env->error, namespace_uri, AXIS2_FAILURE); + AXIS2_PARAM_CHECK(env->error, prefix, AXIS2_FAILURE); + guththila_write_start_element_with_prefix_and_namespace(AXIS2_INTF_TO_IMPL + (writer)->wr, prefix, namespace_uri, localname, env); + return AXIS2_SUCCESS; + +} + +axis2_status_t AXIS2_CALL +guththila_xml_writer_wrapper_write_empty_element( + axiom_xml_writer_t * writer, + const axutil_env_t * env, + axis2_char_t * localname) +{ + AXIS2_ENV_CHECK(env, AXIS2_FAILURE); + AXIS2_PARAM_CHECK(env->error, localname, AXIS2_FAILURE); + guththila_write_empty_element(AXIS2_INTF_TO_IMPL(writer)->wr, localname, env); + return AXIS2_SUCCESS; +} + +axis2_status_t AXIS2_CALL +guththila_xml_writer_wrapper_write_empty_element_with_namespace( + axiom_xml_writer_t * writer, + const axutil_env_t * env, + axis2_char_t * localname, + axis2_char_t * namespace_uri) +{ + AXIS2_ENV_CHECK(env, AXIS2_FAILURE); + AXIS2_PARAM_CHECK(env->error, localname, AXIS2_FAILURE); + AXIS2_PARAM_CHECK(env->error, namespace_uri, AXIS2_FAILURE); + guththila_write_empty_element_with_namespace(AXIS2_INTF_TO_IMPL(writer)->wr, namespace_uri, + localname, env); + return AXIS2_SUCCESS; +} + +axis2_status_t AXIS2_CALL +guththila_xml_writer_wrapper_write_empty_element_with_namespace_prefix( + axiom_xml_writer_t * writer, + const axutil_env_t * env, + axis2_char_t * localname, + axis2_char_t * namespace_uri, + axis2_char_t * prefix) +{ + AXIS2_ENV_CHECK(env, AXIS2_FAILURE); + AXIS2_PARAM_CHECK(env->error, localname, AXIS2_FAILURE); + AXIS2_PARAM_CHECK(env->error, namespace_uri, AXIS2_FAILURE); + AXIS2_PARAM_CHECK(env->error, prefix, AXIS2_FAILURE); + + guththila_write_empty_element_with_prefix_and_namespace(AXIS2_INTF_TO_IMPL + (writer)->wr, prefix, namespace_uri, localname, env); + return AXIS2_SUCCESS; +} + +axis2_status_t AXIS2_CALL +guththila_xml_writer_wrapper_write_end_element( + axiom_xml_writer_t * writer, + const axutil_env_t * env) +{ + AXIS2_ENV_CHECK(env, AXIS2_FAILURE); + guththila_write_end_element(AXIS2_INTF_TO_IMPL(writer)->wr, env); + return AXIS2_SUCCESS; +} + +axis2_status_t AXIS2_CALL +guththila_xml_writer_wrapper_write_end_document( + axiom_xml_writer_t * writer, + const axutil_env_t * env) +{ + AXIS2_ENV_CHECK(env, AXIS2_FAILURE); + guththila_write_end_document(AXIS2_INTF_TO_IMPL(writer)->wr, env); + return AXIS2_SUCCESS; + +} + +axis2_status_t AXIS2_CALL +guththila_xml_writer_wrapper_write_attribute( + axiom_xml_writer_t * writer, + const axutil_env_t * env, + axis2_char_t * localname, + axis2_char_t * value) +{ + if(!value) + value = ""; + + AXIS2_ENV_CHECK(env, AXIS2_FAILURE); + AXIS2_PARAM_CHECK(env->error, localname, AXIS2_FAILURE); + AXIS2_PARAM_CHECK(env->error, value, AXIS2_FAILURE); + guththila_write_attribute(AXIS2_INTF_TO_IMPL(writer)->wr, localname, value, env); + return AXIS2_SUCCESS; +} + +axis2_status_t AXIS2_CALL +guththila_xml_writer_wrapper_write_attribute_with_namespace( + axiom_xml_writer_t * writer, + const axutil_env_t * env, + axis2_char_t * localname, + axis2_char_t * value, + axis2_char_t * namespace_uri) +{ + if(!value) + value = ""; + AXIS2_ENV_CHECK(env, AXIS2_FAILURE); + AXIS2_PARAM_CHECK(env->error, localname, AXIS2_FAILURE); + AXIS2_PARAM_CHECK(env->error, value, AXIS2_FAILURE); + AXIS2_PARAM_CHECK(env->error, namespace_uri, AXIS2_FAILURE); + + guththila_write_attribute_with_namespace(AXIS2_INTF_TO_IMPL(writer)->wr, namespace_uri, + localname, value, env); + return AXIS2_SUCCESS; +} + +axis2_status_t AXIS2_CALL +guththila_xml_writer_wrapper_write_attribute_with_namespace_prefix( + axiom_xml_writer_t * writer, + const axutil_env_t * env, + axis2_char_t * localname, + axis2_char_t * value, + axis2_char_t * namespace_uri, + axis2_char_t * prefix) +{ + AXIS2_ENV_CHECK(env, AXIS2_FAILURE); + AXIS2_PARAM_CHECK(env->error, localname, AXIS2_FAILURE); + AXIS2_PARAM_CHECK(env->error, value, AXIS2_FAILURE); + AXIS2_PARAM_CHECK(env->error, namespace_uri, AXIS2_FAILURE); + AXIS2_PARAM_CHECK(env->error, prefix, AXIS2_FAILURE); + guththila_write_attribute_with_prefix_and_namespace(AXIS2_INTF_TO_IMPL + (writer)->wr, prefix, namespace_uri, localname, value, env); + return AXIS2_SUCCESS; +} + +axis2_status_t AXIS2_CALL +guththila_xml_writer_wrapper_write_namespace( + axiom_xml_writer_t * writer, + const axutil_env_t * env, + axis2_char_t * prefix, + axis2_char_t * namespace_uri) +{ + AXIS2_ENV_CHECK(env, AXIS2_FAILURE); + AXIS2_PARAM_CHECK(env->error, namespace_uri, AXIS2_FAILURE); + /* when default namespace comes is passed, prefix is null */ + if(prefix) + guththila_write_namespace(AXIS2_INTF_TO_IMPL(writer)->wr, prefix, namespace_uri, env); + else + guththila_write_default_namespace(AXIS2_INTF_TO_IMPL(writer)->wr, namespace_uri, env); + return AXIS2_SUCCESS; +} + +axis2_status_t AXIS2_CALL +guththila_xml_writer_wrapper_write_default_namespace( + axiom_xml_writer_t * writer, + const axutil_env_t * env, + axis2_char_t * namespace_uri) +{ + AXIS2_ENV_CHECK(env, AXIS2_FAILURE); + AXIS2_PARAM_CHECK(env->error, namespace_uri, AXIS2_FAILURE); + guththila_write_default_namespace(AXIS2_INTF_TO_IMPL(writer)->wr, namespace_uri, env); + return AXIS2_SUCCESS; +} + +axis2_status_t AXIS2_CALL +guththila_xml_writer_wrapper_write_comment( + axiom_xml_writer_t * writer, + const axutil_env_t * env, + axis2_char_t * value) +{ + AXIS2_ENV_CHECK(env, AXIS2_FAILURE); + AXIS2_PARAM_CHECK(env->error, value, AXIS2_FAILURE); + guththila_write_comment(AXIS2_INTF_TO_IMPL(writer)->wr, value, env); + return AXIS2_SUCCESS; +} + +axis2_status_t AXIS2_CALL +guththila_xml_writer_wrapper_write_processing_instruction( + axiom_xml_writer_t * writer, + const axutil_env_t * env, + axis2_char_t * target) +{ + AXIS2_ENV_CHECK(env, AXIS2_FAILURE); + AXIS2_PARAM_CHECK(env->error, target, AXIS2_FAILURE); + return AXIS2_SUCCESS; +} + +axis2_status_t AXIS2_CALL +guththila_xml_writer_wrapper_write_processing_instruction_data( + axiom_xml_writer_t * writer, + const axutil_env_t * env, + axis2_char_t * target, + axis2_char_t * data) +{ + AXIS2_ENV_CHECK(env, AXIS2_FAILURE); + AXIS2_PARAM_CHECK(env->error, target, AXIS2_FAILURE); + AXIS2_PARAM_CHECK(env->error, data, AXIS2_FAILURE); + return AXIS2_SUCCESS; +} + +axis2_status_t AXIS2_CALL +guththila_xml_writer_wrapper_write_cdata( + axiom_xml_writer_t * writer, + const axutil_env_t * env, + axis2_char_t * data) +{ + AXIS2_ENV_CHECK(env, AXIS2_FAILURE); + AXIS2_PARAM_CHECK(env->error, data, AXIS2_FAILURE); + return AXIS2_SUCCESS; +} + +axis2_status_t AXIS2_CALL +guththila_xml_writer_wrapper_write_dtd( + axiom_xml_writer_t * writer, + const axutil_env_t * env, + axis2_char_t * dtd) +{ + /* AXIS2_ENV_CHECK( env, AXIS2_FAILURE); */ + /* AXIS2_PARAM_CHECK(env->error, dtd, AXIS2_FAILURE); */ + /* return guththila_write_dtd( */ + /* (axutil_env_t *)env, */ + /* AXIS2_INTF_TO_IMPL(writer)->parser, */ + /* dtd); */ + return 0; +} + +axis2_status_t AXIS2_CALL +guththila_xml_writer_wrapper_write_entity_ref( + axiom_xml_writer_t * writer, + const axutil_env_t * env, + axis2_char_t * name) +{ + /* AXIS2_ENV_CHECK( env, AXIS2_FAILURE); */ + /* AXIS2_PARAM_CHECK(env->error, name, AXIS2_FAILURE); */ + /* return guththila_write_entity_ref( */ + /* (axutil_env_t *)env, */ + /* AXIS2_INTF_TO_IMPL(writer)->parser, */ + /* name); */ + return 0; + +} + +axis2_status_t AXIS2_CALL +guththila_xml_writer_wrapper_write_start_document( + axiom_xml_writer_t * writer, + const axutil_env_t * env) +{ + AXIS2_ENV_CHECK(env, AXIS2_FAILURE); + guththila_write_start_document(AXIS2_INTF_TO_IMPL(writer)->wr, env, NULL, NULL); + return AXIS2_SUCCESS; +} + +axis2_status_t AXIS2_CALL +guththila_xml_writer_wrapper_write_start_document_with_version( + axiom_xml_writer_t * writer, + const axutil_env_t * env, + axis2_char_t * version) +{ + AXIS2_ENV_CHECK(env, AXIS2_FAILURE); + AXIS2_PARAM_CHECK(env->error, version, AXIS2_FAILURE); + guththila_write_start_document(AXIS2_INTF_TO_IMPL(writer)->wr, env, NULL, version); + return AXIS2_SUCCESS; +} + +axis2_status_t AXIS2_CALL +guththila_xml_writer_wrapper_write_start_document_with_version_encoding( + axiom_xml_writer_t * writer, + const axutil_env_t * env, + axis2_char_t * encoding, + axis2_char_t * version) +{ + AXIS2_ENV_CHECK(env, AXIS2_FAILURE); + AXIS2_PARAM_CHECK(env->error, encoding, AXIS2_FAILURE); + AXIS2_PARAM_CHECK(env->error, version, AXIS2_FAILURE); + guththila_write_start_document(AXIS2_INTF_TO_IMPL(writer)->wr, env, encoding, version); + return AXIS2_SUCCESS; +} + +axis2_status_t AXIS2_CALL +guththila_xml_writer_wrapper_write_characters( + axiom_xml_writer_t * writer, + const axutil_env_t * env, + axis2_char_t * text) +{ + AXIS2_ENV_CHECK(env, AXIS2_FAILURE); + AXIS2_PARAM_CHECK(env->error, text, AXIS2_FAILURE); + guththila_write_characters(AXIS2_INTF_TO_IMPL(writer)->wr, text, env); + return AXIS2_SUCCESS; +} + +axis2_char_t *AXIS2_CALL +guththila_xml_writer_wrapper_get_prefix( + axiom_xml_writer_t * writer, + const axutil_env_t * env, + axis2_char_t * uri) +{ + AXIS2_ENV_CHECK(env, NULL); + AXIS2_PARAM_CHECK(env->error, uri, NULL); + return guththila_get_prefix_for_namespace(AXIS2_INTF_TO_IMPL(writer)->wr, uri, env); +} + +axis2_status_t AXIS2_CALL +guththila_xml_writer_wrapper_set_prefix( + axiom_xml_writer_t * writer, + const axutil_env_t * env, + axis2_char_t * prefix, + axis2_char_t * uri) +{ + AXIS2_ENV_CHECK(env, AXIS2_FAILURE); + AXIS2_PARAM_CHECK(env->error, prefix, AXIS2_FAILURE); + AXIS2_PARAM_CHECK(env->error, uri, AXIS2_FAILURE); + guththila_write_namespace(AXIS2_INTF_TO_IMPL(writer)->wr, prefix, uri, env); + return AXIS2_SUCCESS; + +} + +axis2_status_t AXIS2_CALL +guththila_xml_writer_wrapper_set_default_prefix( + axiom_xml_writer_t * writer, + const axutil_env_t * env, + axis2_char_t * uri) +{ + AXIS2_ENV_CHECK(env, AXIS2_FAILURE); + AXIS2_PARAM_CHECK(env->error, uri, AXIS2_FAILURE); + guththila_write_default_namespace(AXIS2_INTF_TO_IMPL(writer)->wr, uri, env); + return AXIS2_SUCCESS; +} + +axis2_status_t AXIS2_CALL +guththila_xml_writer_wrapper_write_encoded( + axiom_xml_writer_t * writer, + const axutil_env_t * env, + axis2_char_t * text, + int in_attr) +{ + AXIS2_ENV_CHECK(env, AXIS2_FAILURE); + AXIS2_PARAM_CHECK(env->error, text, AXIS2_FAILURE); + return AXIS2_SUCCESS; +} + +void *AXIS2_CALL +guththila_xml_writer_wrapper_get_xml( + axiom_xml_writer_t * writer, + const axutil_env_t * env) +{ + char *buffer = NULL; + AXIS2_ENV_CHECK(env, AXIS2_FAILURE); + buffer = guththila_get_memory_buffer(AXIS2_INTF_TO_IMPL(writer)->wr, env); + return (void *)buffer; +} + +axis2_status_t AXIS2_CALL +guththila_xml_writer_wrapper_write_raw( + axiom_xml_writer_t * writer, + const axutil_env_t * env, + axis2_char_t * content) +{ + if(!content) + { + return AXIS2_FAILURE; + } + else + { + guththila_write_to_buffer(AXIS2_INTF_TO_IMPL(writer)->wr, (char *)content, (int)strlen( + content), env); + return AXIS2_SUCCESS; + } +} + +unsigned int AXIS2_CALL +guththila_xml_writer_wrapper_get_xml_size( + axiom_xml_writer_t * writer, + const axutil_env_t * env) +{ + AXIS2_ENV_CHECK(env, AXIS2_FAILURE); + return guththila_get_memory_buffer_size(AXIS2_INTF_TO_IMPL(writer)->wr, env); +} + +int AXIS2_CALL +guththila_xml_writer_wrapper_get_type( + axiom_xml_writer_t * writer, + const axutil_env_t * env) +{ + return 0; +} + +axis2_status_t AXIS2_CALL +guththila_xml_writer_wrapper_flush( + axiom_xml_writer_t * writer, + const axutil_env_t * env) +{ + return AXIS2_SUCCESS; +} + +axis2_status_t AXIS2_CALL +guththila_xml_writer_wrapper_end_start_element( + axiom_xml_writer_t * writer, + const axutil_env_t * env) +{ + AXIS2_ENV_CHECK(env, AXIS2_FAILURE); + /* nothing to do , + it is automatically taken care by the libxml2 writer */ + return AXIS2_SUCCESS; +} diff --git a/axiom/src/parser/libxml2/Makefile.am b/axiom/src/parser/libxml2/Makefile.am new file mode 100644 index 0000000..a5b4c75 --- /dev/null +++ b/axiom/src/parser/libxml2/Makefile.am @@ -0,0 +1,17 @@ +lib_LTLIBRARIES = libaxis2_parser.la + + +libaxis2_parser_la_SOURCES = ../xml_reader.c ../xml_writer.c \ + libxml2_reader_wrapper.c libxml2_writer_wrapper.c + +libaxis2_parser_la_LIBADD = @LIBXML2_LIBS@ \ + ../../../../util/src/libaxutil.la + +libaxis2_parser_la_LDFLAGS = -version-info $(VERSION_NO) +libaxis2_libxml2_la_LDFLAGS = -version-info $(VERSION_NO) + + +INCLUDES = -I$(top_builddir)/include \ + -I$(top_builddir)/src/parser \ + -I ../../../../util/include \ + @LIBXML2_CFLAGS@ diff --git a/axiom/src/parser/libxml2/libxml2_reader_wrapper.c b/axiom/src/parser/libxml2/libxml2_reader_wrapper.c new file mode 100644 index 0000000..2510d49 --- /dev/null +++ b/axiom/src/parser/libxml2/libxml2_reader_wrapper.c @@ -0,0 +1,949 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + */ + +#include <axiom_xml_reader.h> +#include <libxml/xmlreader.h> +#include <libxml/parser.h> +#include <axutil_utils_defines.h> +#include <axutil_utils.h> +#include <string.h> +#include <axutil_string.h> + + +int AXIS2_CALL axis2_libxml2_reader_wrapper_next( + axiom_xml_reader_t * parser, + const axutil_env_t * env); + +void AXIS2_CALL axis2_libxml2_reader_wrapper_free( + axiom_xml_reader_t * parser, + const axutil_env_t * env); + +int AXIS2_CALL axis2_libxml2_reader_wrapper_get_attribute_count( + axiom_xml_reader_t * parser, + const axutil_env_t * env); + +axis2_char_t *AXIS2_CALL +axis2_libxml2_reader_wrapper_get_attribute_name_by_number( + axiom_xml_reader_t * parser, + const axutil_env_t * env, + int i); + +axis2_char_t *AXIS2_CALL +axis2_libxml2_reader_wrapper_get_attribute_prefix_by_number( + axiom_xml_reader_t * parser, + const axutil_env_t * env, + int i); + +axis2_char_t *AXIS2_CALL +axis2_libxml2_reader_wrapper_get_attribute_value_by_number( + axiom_xml_reader_t * parser, + const axutil_env_t * env, + int i); + +axis2_char_t *AXIS2_CALL +axis2_libxml2_reader_wrapper_get_attribute_namespace_by_number( + axiom_xml_reader_t * parser, + const axutil_env_t * env, + int i); + +axis2_char_t *AXIS2_CALL axis2_libxml2_reader_wrapper_get_value( + axiom_xml_reader_t * parser, + const axutil_env_t * env); + +int AXIS2_CALL axis2_libxml2_reader_wrapper_get_namespace_count( + axiom_xml_reader_t * parser, + const axutil_env_t * env); + +axis2_char_t *AXIS2_CALL +axis2_libxml2_reader_wrapper_get_namespace_uri_by_number( + axiom_xml_reader_t * parser, + const axutil_env_t * env, + int i); + +axis2_char_t *AXIS2_CALL +axis2_libxml2_reader_wrapper_get_namespace_prefix_by_number( + axiom_xml_reader_t * parser, + const axutil_env_t * env, + int i); + +axis2_char_t *AXIS2_CALL axis2_libxml2_reader_wrapper_get_prefix( + axiom_xml_reader_t * parser, + const axutil_env_t * env); + +axis2_char_t *AXIS2_CALL axis2_libxml2_reader_wrapper_get_name( + axiom_xml_reader_t * parser, + const axutil_env_t * env); + +axis2_char_t *AXIS2_CALL axis2_libxml2_reader_wrapper_get_pi_target( + axiom_xml_reader_t * parser, + const axutil_env_t * env); + +axis2_char_t *AXIS2_CALL axis2_libxml2_reader_wrapper_get_pi_data( + axiom_xml_reader_t * parser, + const axutil_env_t * env); + +axis2_char_t *AXIS2_CALL axis2_libxml2_reader_wrapper_get_dtd( + axiom_xml_reader_t * parser, + const axutil_env_t * env); + +void AXIS2_CALL axis2_libxml2_reader_wrapper_xml_free( + axiom_xml_reader_t * parser, + const axutil_env_t * env, + void *data); + +axis2_char_t *AXIS2_CALL axis2_libxml2_reader_wrapper_get_char_set_encoding( + axiom_xml_reader_t * parser, + const axutil_env_t * env); + +axis2_char_t *AXIS2_CALL axis2_libxml2_reader_wrapper_get_namespace_uri( + axiom_xml_reader_t * parser, + const axutil_env_t * env); + +axis2_char_t *AXIS2_CALL +axis2_libxml2_reader_wrapper_get_namespace_uri_by_prefix( + axiom_xml_reader_t * parser, + const axutil_env_t * env, + axis2_char_t * prefix); + +axis2_status_t +axis2_libxml2_reader_wrapper_fill_maps( + axiom_xml_reader_t * parser, + const axutil_env_t * env); + +void +axis2_libxml2_reader_wrapper_error_handler( + void *arg, + const char *msg, + int severities, + void *locator_ptr); + +static int +axis2_libxml2_reader_wrapper_read_input_callback( + void *ctx, + char *buffer, + int size); + +static int +axis2_libxml2_reader_wrapper_close_input_callback( + void *ctx); + +typedef struct axis2_libxml2_reader_wrapper_impl_t +{ + axiom_xml_reader_t parser; + + xmlTextReaderPtr reader; + + int current_event; + int current_attribute_count; + int current_namespace_count; + int event_map[18]; + + void *ctx; + /* assuming that max ns and attribute will be 20 */ + + int *namespace_map; + int *attribute_map; + + AXIS2_READ_INPUT_CALLBACK read_input_callback; + + AXIS2_CLOSE_INPUT_CALLBACK close_input_callback; + +} axis2_libxml2_reader_wrapper_impl_t; + +#define AXIS2_INTF_TO_IMPL(p) ((axis2_libxml2_reader_wrapper_impl_t*)p) +#define AXIS2_IMPL_TO_INTF(p) &(p->parser) + +static const axiom_xml_reader_ops_t axiom_xml_reader_ops_var = { axis2_libxml2_reader_wrapper_next, + axis2_libxml2_reader_wrapper_free, axis2_libxml2_reader_wrapper_get_attribute_count, + axis2_libxml2_reader_wrapper_get_attribute_name_by_number, + axis2_libxml2_reader_wrapper_get_attribute_prefix_by_number, + axis2_libxml2_reader_wrapper_get_attribute_value_by_number, + axis2_libxml2_reader_wrapper_get_attribute_namespace_by_number, + axis2_libxml2_reader_wrapper_get_value, axis2_libxml2_reader_wrapper_get_namespace_count, + axis2_libxml2_reader_wrapper_get_namespace_uri_by_number, + axis2_libxml2_reader_wrapper_get_namespace_prefix_by_number, + axis2_libxml2_reader_wrapper_get_prefix, axis2_libxml2_reader_wrapper_get_name, + axis2_libxml2_reader_wrapper_get_pi_target, axis2_libxml2_reader_wrapper_get_pi_data, + axis2_libxml2_reader_wrapper_get_dtd, axis2_libxml2_reader_wrapper_xml_free, + axis2_libxml2_reader_wrapper_get_char_set_encoding, + axis2_libxml2_reader_wrapper_get_namespace_uri, + axis2_libxml2_reader_wrapper_get_namespace_uri_by_prefix }; + +static axis2_status_t +axis2_libxml2_reader_wrapper_init_map( + axis2_libxml2_reader_wrapper_impl_t * parser) +{ + int i = 0; + if(parser) + { + for(i = 0; i < 18; i++) + { + parser->event_map[i] = -1; + } + + parser->event_map[XML_READER_TYPE_ELEMENT] = AXIOM_XML_READER_START_ELEMENT; + parser->event_map[XML_READER_TYPE_DOCUMENT] = AXIOM_XML_READER_START_DOCUMENT; + parser->event_map[XML_READER_TYPE_TEXT] = AXIOM_XML_READER_CHARACTER; + parser->event_map[XML_READER_TYPE_CDATA] = AXIOM_XML_READER_CHARACTER; + parser->event_map[XML_READER_TYPE_SIGNIFICANT_WHITESPACE] = AXIOM_XML_READER_SPACE; + parser->event_map[XML_READER_TYPE_WHITESPACE] = AXIOM_XML_READER_SPACE; + parser->event_map[XML_READER_TYPE_END_ELEMENT] = AXIOM_XML_READER_END_ELEMENT; + parser->event_map[XML_READER_TYPE_ENTITY_REFERENCE] = AXIOM_XML_READER_ENTITY_REFERENCE; + parser->event_map[XML_READER_TYPE_END_ENTITY] = AXIOM_XML_READER_SPACE; + parser->event_map[XML_READER_TYPE_ENTITY] = AXIOM_XML_READER_SPACE; + parser->event_map[XML_READER_TYPE_PROCESSING_INSTRUCTION] + = AXIOM_XML_READER_PROCESSING_INSTRUCTION; + parser->event_map[XML_READER_TYPE_COMMENT] = AXIOM_XML_READER_COMMENT; + parser->event_map[XML_READER_TYPE_DOCUMENT_TYPE] = AXIOM_XML_READER_DOCUMENT_TYPE; + return AXIS2_SUCCESS; + } + return AXIS2_FAILURE; +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +axiom_xml_reader_init() +{ + xmlInitParser(); + return AXIS2_SUCCESS; +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +axiom_xml_reader_cleanup() +{ + xmlCleanupParser(); + return AXIS2_SUCCESS; +} + +static axis2_libxml2_reader_wrapper_impl_t* +libxml2_reader_wrapper_create( + const axutil_env_t *env) +{ + axis2_libxml2_reader_wrapper_impl_t *wrapper_impl = NULL; + wrapper_impl = (axis2_libxml2_reader_wrapper_impl_t *)AXIS2_MALLOC(env->allocator, + sizeof(axis2_libxml2_reader_wrapper_impl_t)); + + if(!wrapper_impl) + { + AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE); + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "No memory. Cannot create libxml2 reader wrapper"); + return NULL; + } + memset(wrapper_impl, 0, sizeof(axis2_libxml2_reader_wrapper_impl_t)); + wrapper_impl->attribute_map = NULL; + wrapper_impl->namespace_map = NULL; + wrapper_impl->close_input_callback = NULL; + wrapper_impl->read_input_callback = NULL; + wrapper_impl->ctx = NULL; + wrapper_impl->current_namespace_count = 0; + wrapper_impl->current_attribute_count = 0; + wrapper_impl->current_event = -1; + return wrapper_impl; +} + +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) +{ + + axis2_libxml2_reader_wrapper_impl_t *wrapper_impl = NULL; + AXIS2_ENV_CHECK(env, NULL); + AXIS2_PARAM_CHECK(env->error, filename, NULL); + + wrapper_impl = libxml2_reader_wrapper_create(env); + if(!wrapper_impl) + { + return NULL; + } + + wrapper_impl->reader = xmlReaderForFile(filename, encoding, XML_PARSE_RECOVER); + if(!(wrapper_impl->reader)) + { + AXIS2_FREE(env->allocator, wrapper_impl); + AXIS2_HANDLE_ERROR(env, AXIS2_ERROR_CREATING_XML_STREAM_READER, AXIS2_FAILURE); + return NULL; + } + + xmlTextReaderSetErrorHandler(wrapper_impl->reader, + (xmlTextReaderErrorFunc)axis2_libxml2_reader_wrapper_error_handler, (void *)env); + wrapper_impl->current_event = -1; + wrapper_impl->ctx = NULL; + axis2_libxml2_reader_wrapper_init_map(wrapper_impl); + + wrapper_impl->parser.ops = &axiom_xml_reader_ops_var; + return &(wrapper_impl->parser); +} + +AXIS2_EXTERN axiom_xml_reader_t *AXIS2_CALL +axiom_xml_reader_create_for_io( + const axutil_env_t * env, + AXIS2_READ_INPUT_CALLBACK read_input_callback, + AXIS2_CLOSE_INPUT_CALLBACK close_input_callback, + void *ctx, + const axis2_char_t * encoding) +{ + axis2_libxml2_reader_wrapper_impl_t *wrapper_impl = NULL; + + AXIS2_ENV_CHECK(env, NULL); + + if(!read_input_callback) + { + return NULL; + } + + wrapper_impl = libxml2_reader_wrapper_create(env); + if(!wrapper_impl) + { + return NULL; + } + wrapper_impl->close_input_callback = NULL; + wrapper_impl->read_input_callback = NULL; + wrapper_impl->read_input_callback = read_input_callback; + wrapper_impl->close_input_callback = close_input_callback; + wrapper_impl->ctx = ctx; + if(wrapper_impl->close_input_callback) + { + wrapper_impl->reader = xmlReaderForIO(axis2_libxml2_reader_wrapper_read_input_callback, + axis2_libxml2_reader_wrapper_close_input_callback, wrapper_impl, NULL, encoding, + XML_PARSE_RECOVER); + } + else + { + wrapper_impl->reader = xmlReaderForIO(axis2_libxml2_reader_wrapper_read_input_callback, + NULL, wrapper_impl, NULL, encoding, XML_PARSE_RECOVER); + } + if(!(wrapper_impl->reader)) + { + AXIS2_FREE(env->allocator, wrapper_impl); + AXIS2_HANDLE_ERROR(env, AXIS2_ERROR_CREATING_XML_STREAM_READER, AXIS2_FAILURE); + return NULL; + } + + xmlTextReaderSetErrorHandler(wrapper_impl->reader, + (xmlTextReaderErrorFunc)axis2_libxml2_reader_wrapper_error_handler, (void *)env); + + wrapper_impl->current_event = -1; + + axis2_libxml2_reader_wrapper_init_map(wrapper_impl); + + wrapper_impl->parser.ops = &axiom_xml_reader_ops_var; + return &(wrapper_impl->parser); +} + +AXIS2_EXTERN axiom_xml_reader_t *AXIS2_CALL +axiom_xml_reader_create_for_memory( + const axutil_env_t * env, + void *container, + int size, + const axis2_char_t * encoding, + int type) +{ + axis2_libxml2_reader_wrapper_impl_t *wrapper_impl = NULL; + + AXIS2_PARAM_CHECK(env->error, container, NULL); + + wrapper_impl = libxml2_reader_wrapper_create(env); + if(!wrapper_impl) + { + return NULL; + } + wrapper_impl->close_input_callback = NULL; + wrapper_impl->read_input_callback = NULL; + wrapper_impl->ctx = NULL; + + if(AXIS2_XML_PARSER_TYPE_BUFFER == type) + { + wrapper_impl->reader = xmlReaderForMemory((axis2_char_t *)container, size, NULL, encoding, + XML_PARSE_RECOVER); + } + else if(AXIS2_XML_PARSER_TYPE_DOC == type) + { + wrapper_impl->reader = xmlReaderWalker((xmlDocPtr)container); + } + else + { + AXIS2_FREE(env->allocator, wrapper_impl); + AXIS2_HANDLE_ERROR(env, AXIS2_ERROR_XML_PARSER_INVALID_MEM_TYPE, AXIS2_FAILURE); + return NULL; + } + + if(!(wrapper_impl->reader)) + { + AXIS2_FREE(env->allocator, wrapper_impl); + AXIS2_HANDLE_ERROR(env, AXIS2_ERROR_CREATING_XML_STREAM_READER, AXIS2_FAILURE); + return NULL; + } + + if(AXIS2_XML_PARSER_TYPE_BUFFER == type) + { + xmlTextReaderSetErrorHandler(wrapper_impl->reader, + (xmlTextReaderErrorFunc)axis2_libxml2_reader_wrapper_error_handler, (void *)env); + } + + wrapper_impl->current_event = -1; + + axis2_libxml2_reader_wrapper_init_map(wrapper_impl); + + wrapper_impl->parser.ops = &axiom_xml_reader_ops_var; + return &(wrapper_impl->parser); +} + +int AXIS2_CALL +axis2_libxml2_reader_wrapper_next( + axiom_xml_reader_t * parser, + const axutil_env_t * env) +{ + int ret_val = 0; + int node = 2; + int empty_check = 0; + axis2_libxml2_reader_wrapper_impl_t *parser_impl; + AXIS2_ENV_CHECK(env, -1); + parser_impl = AXIS2_INTF_TO_IMPL(parser); + ret_val = xmlTextReaderRead(parser_impl->reader); + if(ret_val == 0) + { + AXIS2_LOG_DEBUG(env->log, AXIS2_LOG_SI, "xml stream is over "); + } + if(ret_val == -1) + { + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, " error occurred in reading xml stream "); + return -1; + } + + if(ret_val == 1) + { + node = xmlTextReaderNodeType(parser_impl->reader); + parser_impl->current_event = parser_impl->event_map[node]; + parser_impl->current_attribute_count = 0; + parser_impl->current_namespace_count = 0; + + if(node == XML_READER_TYPE_ELEMENT) + { + empty_check = xmlTextReaderIsEmptyElement(parser_impl->reader); + axis2_libxml2_reader_wrapper_fill_maps(parser, env); + } + if(empty_check == 1) + { + parser_impl->current_event = AXIOM_XML_READER_EMPTY_ELEMENT; + return AXIOM_XML_READER_EMPTY_ELEMENT; + } + return parser_impl->event_map[node]; + } + else + { + return -1; + } +} + +/** + * If your application crashes here, it may be due to an earlier call to + * xmlCleanupParser() function. In client API, op_client create function has a call + * to axiom_xml_reader_init and op_client_free function has a call to axiom_xml_reader_cleanup + * function. You can avoid the call to axiom_xml_reader_cleanup using + * axis2_options_set_xml_parser_reset function in client API. + * refer to jira issue: https://issues.apache.org/jira/browse/AXIS2C-884 + */ +void AXIS2_CALL +axis2_libxml2_reader_wrapper_free( + axiom_xml_reader_t * parser, + const axutil_env_t * env) +{ + axis2_libxml2_reader_wrapper_impl_t *parser_impl = NULL; + parser_impl = AXIS2_INTF_TO_IMPL(parser); + if(parser_impl->ctx) + { + AXIS2_FREE(env->allocator, parser_impl->ctx); + } + + if(parser_impl->reader) + { + xmlTextReaderClose(parser_impl->reader); + xmlFreeTextReader(parser_impl->reader); + } + if(parser_impl->namespace_map) + { + AXIS2_FREE(env->allocator, parser_impl->namespace_map); + parser_impl->namespace_map = NULL; + } + if(parser_impl->attribute_map) + { + AXIS2_FREE(env->allocator, parser_impl->attribute_map); + parser_impl->attribute_map = NULL; + } + AXIS2_FREE(env->allocator, AXIS2_INTF_TO_IMPL(parser)); + return; +} + +int AXIS2_CALL +axis2_libxml2_reader_wrapper_get_attribute_count( + axiom_xml_reader_t * parser, + const axutil_env_t * env) +{ + axis2_libxml2_reader_wrapper_impl_t *parser_impl = NULL; + AXIS2_ENV_CHECK(env, AXIS2_FAILURE); + parser_impl = AXIS2_INTF_TO_IMPL(parser); + if(parser_impl->current_event == AXIOM_XML_READER_START_ELEMENT || parser_impl->current_event + == AXIOM_XML_READER_EMPTY_ELEMENT) + { + return parser_impl->current_attribute_count; + } + else + { + return 0; + } +} + +axis2_char_t *AXIS2_CALL +axis2_libxml2_reader_wrapper_get_attribute_name_by_number( + axiom_xml_reader_t * parser, + const axutil_env_t * env, + int i) +{ + axis2_libxml2_reader_wrapper_impl_t *parser_impl; + AXIS2_ENV_CHECK(env, NULL); + parser_impl = AXIS2_INTF_TO_IMPL(parser); + + if(parser_impl->current_attribute_count > 0 && parser_impl->current_attribute_count >= i) + { + int ret = + xmlTextReaderMoveToAttributeNo(parser_impl->reader, parser_impl->attribute_map[i]); + if(ret == 1) + { + return (axis2_char_t *)xmlTextReaderLocalName(parser_impl->reader); + } + else + { + return NULL; + } + } + return NULL; +} + +axis2_char_t *AXIS2_CALL +axis2_libxml2_reader_wrapper_get_attribute_prefix_by_number( + axiom_xml_reader_t * parser, + const axutil_env_t * env, + int i) +{ + axis2_libxml2_reader_wrapper_impl_t *parser_impl = NULL; + AXIS2_ENV_CHECK(env, NULL); + parser_impl = AXIS2_INTF_TO_IMPL(parser); + + if(parser_impl->current_attribute_count > 0 && parser_impl->current_attribute_count >= i) + { + int ret = + xmlTextReaderMoveToAttributeNo(parser_impl->reader, parser_impl->attribute_map[i]); + if(ret == 1) + { + return (axis2_char_t *)xmlTextReaderPrefix(parser_impl->reader); + } + else + { + return NULL; + } + } + return NULL; +} + +axis2_char_t *AXIS2_CALL +axis2_libxml2_reader_wrapper_get_attribute_value_by_number( + axiom_xml_reader_t * parser, + const axutil_env_t * env, + int i) +{ + + axis2_libxml2_reader_wrapper_impl_t *parser_impl; + AXIS2_ENV_CHECK(env, NULL); + parser_impl = AXIS2_INTF_TO_IMPL(parser); + + if(parser_impl->current_attribute_count > 0 && parser_impl->current_attribute_count >= i) + { + int ret = + xmlTextReaderMoveToAttributeNo(parser_impl->reader, parser_impl->attribute_map[i]); + if(ret == 1) + { + return (axis2_char_t *)xmlTextReaderValue(parser_impl->reader); + } + else + { + return NULL; + } + } + return NULL; +} + +axis2_char_t *AXIS2_CALL +axis2_libxml2_reader_wrapper_get_attribute_namespace_by_number( + axiom_xml_reader_t * parser, + const axutil_env_t * env, + int i) +{ + axis2_libxml2_reader_wrapper_impl_t *parser_impl; + AXIS2_ENV_CHECK(env, NULL); + parser_impl = AXIS2_INTF_TO_IMPL(parser); + + if(parser_impl->current_attribute_count > 0 && parser_impl->current_attribute_count >= i) + { + int ret = + xmlTextReaderMoveToAttributeNo(parser_impl->reader, parser_impl->attribute_map[i]); + + if(ret == 1) + { + return (axis2_char_t *)xmlTextReaderNamespaceUri(parser_impl-> reader); + } + else + { + return NULL; + } + } + return NULL; +} + +axis2_char_t *AXIS2_CALL +axis2_libxml2_reader_wrapper_get_value( + axiom_xml_reader_t * parser, + const axutil_env_t * env) +{ + axis2_libxml2_reader_wrapper_impl_t *parser_impl = NULL; + + AXIS2_ENV_CHECK(env, NULL); + parser_impl = AXIS2_INTF_TO_IMPL(parser); + return (axis2_char_t *)xmlTextReaderValue(parser_impl->reader); + +} + +int AXIS2_CALL +axis2_libxml2_reader_wrapper_get_namespace_count( + axiom_xml_reader_t * parser, + const axutil_env_t * env) +{ + axis2_libxml2_reader_wrapper_impl_t *parser_impl = NULL; + AXIS2_ENV_CHECK(env, AXIS2_FAILURE); + parser_impl = AXIS2_INTF_TO_IMPL(parser); + if(parser_impl->current_event == AXIOM_XML_READER_START_ELEMENT || parser_impl->current_event + == AXIOM_XML_READER_EMPTY_ELEMENT) + { + return parser_impl->current_namespace_count; + } + else + { + return 0; + } +} + +axis2_char_t *AXIS2_CALL +axis2_libxml2_reader_wrapper_get_namespace_uri_by_number( + axiom_xml_reader_t * parser, + const axutil_env_t * env, + int i) +{ + axis2_libxml2_reader_wrapper_impl_t *parser_impl = NULL; + AXIS2_ENV_CHECK(env, NULL); + parser_impl = AXIS2_INTF_TO_IMPL(parser); + + if(parser_impl->current_namespace_count > 0 && parser_impl->current_namespace_count >= i) + { + + int ret = + xmlTextReaderMoveToAttributeNo(parser_impl->reader, parser_impl->namespace_map[i]); + if(ret == 1) + { + return (axis2_char_t *)xmlTextReaderValue(parser_impl->reader); + } + else + return NULL; + } + return NULL; +} + +axis2_char_t *AXIS2_CALL +axis2_libxml2_reader_wrapper_get_namespace_prefix_by_number( + axiom_xml_reader_t * parser, + const axutil_env_t * env, + int i) +{ + axis2_libxml2_reader_wrapper_impl_t *parser_impl = NULL; + AXIS2_ENV_CHECK(env, NULL); + parser_impl = AXIS2_INTF_TO_IMPL(parser); + + if(parser_impl->current_namespace_count > 0 && parser_impl->current_namespace_count >= i) + { + int ret = + xmlTextReaderMoveToAttributeNo(parser_impl->reader, parser_impl->namespace_map[i]); + + if(ret == 1) + { + return (axis2_char_t *)xmlTextReaderLocalName(parser_impl->reader); + } + else + { + return NULL; + } + } + return NULL; +} + +axis2_char_t *AXIS2_CALL +axis2_libxml2_reader_wrapper_get_prefix( + axiom_xml_reader_t * parser, + const axutil_env_t * env) +{ + axis2_libxml2_reader_wrapper_impl_t *parser_impl = NULL; + parser_impl = AXIS2_INTF_TO_IMPL(parser); + xmlTextReaderMoveToElement(parser_impl->reader); + return (axis2_char_t *)xmlTextReaderPrefix(parser_impl->reader); +} + +axis2_char_t *AXIS2_CALL +axis2_libxml2_reader_wrapper_get_name( + axiom_xml_reader_t * parser, + const axutil_env_t * env) +{ + axis2_libxml2_reader_wrapper_impl_t *parser_impl = NULL; + parser_impl = AXIS2_INTF_TO_IMPL(parser); + xmlTextReaderMoveToElement(parser_impl->reader); + return (axis2_char_t *)xmlTextReaderLocalName(parser_impl->reader); +} + +axis2_char_t *AXIS2_CALL +axis2_libxml2_reader_wrapper_get_pi_target( + axiom_xml_reader_t * parser, + const axutil_env_t * env) +{ + axis2_libxml2_reader_wrapper_impl_t *parser_impl = NULL; + parser_impl = AXIS2_INTF_TO_IMPL(parser); + if(parser_impl->current_event == AXIOM_XML_READER_PROCESSING_INSTRUCTION) + { + return (axis2_char_t *)xmlTextReaderLocalName(parser_impl->reader); + } + else + { + return NULL; + } +} + +axis2_char_t *AXIS2_CALL +axis2_libxml2_reader_wrapper_get_dtd( + axiom_xml_reader_t * parser, + const axutil_env_t * env) +{ + axis2_libxml2_reader_wrapper_impl_t *parser_impl = NULL; + parser_impl = AXIS2_INTF_TO_IMPL(parser); + if(parser_impl->current_event == AXIOM_XML_READER_DOCUMENT_TYPE) + { + return (axis2_char_t *)xmlTextReaderLocalName(parser_impl->reader); + } + else + { + return NULL; + } +} + +axis2_char_t *AXIS2_CALL +axis2_libxml2_reader_wrapper_get_pi_data( + axiom_xml_reader_t * parser, + const axutil_env_t * env) +{ + axis2_libxml2_reader_wrapper_impl_t *parser_impl = NULL; + parser_impl = AXIS2_INTF_TO_IMPL(parser); + if(parser_impl->current_event == AXIOM_XML_READER_PROCESSING_INSTRUCTION) + { + return (axis2_char_t *)xmlTextReaderValue(parser_impl->reader); + } + else + { + return NULL; + } +} + +void AXIS2_CALL +axis2_libxml2_reader_wrapper_xml_free( + axiom_xml_reader_t * parser, + const axutil_env_t * env, + void *data) +{ + AXIS2_ENV_CHECK(env, void); + if(data) + xmlFree(data); + return; +} + +axis2_char_t *AXIS2_CALL +axis2_libxml2_reader_wrapper_get_char_set_encoding( + axiom_xml_reader_t * parser, + const axutil_env_t * env) +{ + axis2_libxml2_reader_wrapper_impl_t *reader_impl = NULL; + reader_impl = AXIS2_INTF_TO_IMPL(parser); + return (axis2_char_t *)xmlTextReaderConstEncoding(reader_impl->reader); +} + +axis2_char_t *AXIS2_CALL +axis2_libxml2_reader_wrapper_get_namespace_uri( + axiom_xml_reader_t * parser, + const axutil_env_t * env) +{ + axis2_libxml2_reader_wrapper_impl_t *parser_impl = NULL; + parser_impl = AXIS2_INTF_TO_IMPL(parser); + return (axis2_char_t *)xmlTextReaderNamespaceUri(parser_impl->reader); +} + +axis2_char_t *AXIS2_CALL +axis2_libxml2_reader_wrapper_get_namespace_uri_by_prefix( + axiom_xml_reader_t * parser, + const axutil_env_t * env, + axis2_char_t * prefix) +{ + axis2_libxml2_reader_wrapper_impl_t *parser_impl = NULL; + parser_impl = AXIS2_INTF_TO_IMPL(parser); + if(!prefix || axutil_strcmp(prefix, "") == 0) + { + return NULL; + } + return (axis2_char_t *)xmlTextReaderLookupNamespace(parser_impl->reader, + (const xmlChar *)prefix); +} + +axis2_status_t +axis2_libxml2_reader_wrapper_fill_maps( + axiom_xml_reader_t * parser, + const axutil_env_t * env) +{ + int libxml2_attribute_count = 0; + int attr_count = 0; + int ns_count = 0; + int i = 0; + char *q_name = NULL; + axis2_libxml2_reader_wrapper_impl_t *parser_impl = NULL; + int map_size = 0; + AXIS2_ENV_CHECK(env, AXIS2_FAILURE); + parser_impl = AXIS2_INTF_TO_IMPL(parser); + + libxml2_attribute_count = xmlTextReaderAttributeCount(parser_impl->reader); + if(libxml2_attribute_count == 0) + { + parser_impl->current_attribute_count = 0; + parser_impl->current_namespace_count = 0; + return AXIS2_SUCCESS; + } + map_size = libxml2_attribute_count + 1; + if(parser_impl->namespace_map) + { + AXIS2_FREE(env->allocator, parser_impl->namespace_map); + parser_impl->namespace_map = NULL; + } + if(parser_impl->attribute_map) + { + AXIS2_FREE(env->allocator, parser_impl->attribute_map); + parser_impl->attribute_map = NULL; + } + parser_impl->attribute_map = AXIS2_MALLOC(env->allocator, sizeof(int) * map_size); + memset(parser_impl->attribute_map, 0, map_size * sizeof(int)); + + parser_impl->namespace_map = AXIS2_MALLOC(env->allocator, sizeof(int) * map_size); + memset(parser_impl->namespace_map, 0, map_size * sizeof(int)); + + for(i = 0; i < map_size; i++) + { + parser_impl->namespace_map[i] = -1; + parser_impl->attribute_map[i] = -1; + } + + for(i = 0; i < libxml2_attribute_count; i++) + { + xmlTextReaderMoveToAttributeNo(parser_impl->reader, i); + q_name = (char *)xmlTextReaderName(parser_impl->reader); + if(q_name) + { + if((strcmp(q_name, "xmlns") == 0) || (strncmp(q_name, "xmlns:", 6) == 0)) + { + /* found a namespace */ + ns_count++; + parser_impl->namespace_map[ns_count] = i; + } + else + { + /* found an attribute */ + attr_count++; + parser_impl->attribute_map[attr_count] = i; + } + + xmlFree(q_name); + q_name = NULL; + } + + parser_impl->current_attribute_count = attr_count; + parser_impl->current_namespace_count = ns_count; + } + return AXIS2_SUCCESS; +} + +static int +axis2_libxml2_reader_wrapper_read_input_callback( + void *ctx, + char *buffer, + int size) +{ + return ((axis2_libxml2_reader_wrapper_impl_t *)ctx)-> read_input_callback(buffer, size, + ((axis2_libxml2_reader_wrapper_impl_t *)ctx)->ctx); +} + +void +axis2_libxml2_reader_wrapper_error_handler( + void *arg, + const char *msg, + int severities, + void *locator_ptr) +{ + const axutil_env_t *env = NULL; + env = (const axutil_env_t *)arg; + + switch(severities) + { + case XML_PARSER_SEVERITY_VALIDITY_WARNING: + { + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "%s VALIDITY WARNTING", msg); + } + break; + case XML_PARSER_SEVERITY_VALIDITY_ERROR: + { + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "%s -- VALIDITY ERROR", msg); + } + break; + case XML_PARSER_SEVERITY_WARNING: + { + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "%s -- VALIDITY ERROR", msg); + } + break; + case XML_PARSER_SEVERITY_ERROR: + { + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "%s -- SEVERITY_ERROR", msg); + } + break; + default: + break; + } +} + +static int +axis2_libxml2_reader_wrapper_close_input_callback( + void *ctx) +{ + return ((axis2_libxml2_reader_wrapper_impl_t *)ctx)-> close_input_callback( + ((axis2_libxml2_reader_wrapper_impl_t *)ctx)-> ctx); +} diff --git a/axiom/src/parser/libxml2/libxml2_writer_wrapper.c b/axiom/src/parser/libxml2/libxml2_writer_wrapper.c new file mode 100644 index 0000000..4c889d4 --- /dev/null +++ b/axiom/src/parser/libxml2/libxml2_writer_wrapper.c @@ -0,0 +1,1571 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + */ + +#include <libxml/xmlwriter.h> +#include <axutil_utils.h> +#include <axutil_utils_defines.h> +#include <axutil_env.h> +#include <axiom_xml_writer.h> +#include <axutil_string.h> +#include <string.h> +#include <axutil_stack.h> +#include <axutil_hash.h> +#include <axutil_array_list.h> + +/*******************************************************************************/ + +#define ENCODING "ISO-8859-1" + +#define AXIS2_XMLNS_NAMESPACE_URI "http://www.w3.org/XML/1998/namespace" +#define AXIS2_XMLNS_PREFIX "xml" + +typedef struct uri_prefix_element +{ + axis2_char_t *prefix; + + axis2_char_t *uri; + + axis2_char_t *real_prefix; + + axis2_char_t *key; + +} uri_prefix_element_t; + +typedef struct axis2_libxml2_writer_wrapper_impl +{ + axiom_xml_writer_t writer; + + xmlTextWriterPtr xml_writer; + + xmlBufferPtr buffer; + + xmlDocPtr doc; + + int writer_type; + + axis2_char_t *encoding; + + int is_prefix_defaulting; + + int compression; + + axutil_stack_t *stack; + + axis2_bool_t in_empty_element; + + axis2_bool_t in_start_element; + + axutil_hash_t *uri_prefix_map; + + uri_prefix_element_t *default_lang_namespace; + +} axis2_libxml2_writer_wrapper_impl_t; + +#define AXIS2_INTF_TO_IMPL(p) ((axis2_libxml2_writer_wrapper_impl_t*)p) + +void AXIS2_CALL axis2_libxml2_writer_wrapper_free( + axiom_xml_writer_t * writer, + const axutil_env_t * env); + +axis2_status_t AXIS2_CALL +axis2_libxml2_writer_wrapper_write_start_element( + axiom_xml_writer_t * writer, + const axutil_env_t * env, + axis2_char_t * localname); + +axis2_status_t AXIS2_CALL +axis2_libxml2_writer_wrapper_end_start_element( + axiom_xml_writer_t * writer, + const axutil_env_t * env); + +axis2_status_t AXIS2_CALL +axis2_libxml2_writer_wrapper_write_start_element_with_namespace( + axiom_xml_writer_t * writer, + const axutil_env_t * env, + axis2_char_t * localname, + axis2_char_t * namespace_uri); + +axis2_status_t AXIS2_CALL +axis2_libxml2_writer_wrapper_write_start_element_with_namespace_prefix( + axiom_xml_writer_t * writer, + const axutil_env_t * env, + axis2_char_t * localname, + axis2_char_t * namespace_uri, + axis2_char_t * prefix); + +axis2_status_t AXIS2_CALL +axis2_libxml2_writer_wrapper_write_empty_element( + axiom_xml_writer_t * writer, + const axutil_env_t * env, + axis2_char_t * localname); + +axis2_status_t AXIS2_CALL +axis2_libxml2_writer_wrapper_write_empty_element_with_namespace( + axiom_xml_writer_t * writer, + const axutil_env_t * env, + axis2_char_t * localname, + axis2_char_t * namespace_uri); + +axis2_status_t AXIS2_CALL +axis2_libxml2_writer_wrapper_write_empty_element_with_namespace_prefix( + axiom_xml_writer_t * writer, + const axutil_env_t * env, + axis2_char_t * localname, + axis2_char_t * namespace_uri, + axis2_char_t * prefix); + +axis2_status_t AXIS2_CALL +axis2_libxml2_writer_wrapper_write_end_element( + axiom_xml_writer_t * writer, + const axutil_env_t * env); + +axis2_status_t AXIS2_CALL +axis2_libxml2_writer_wrapper_write_end_document( + axiom_xml_writer_t * writer, + const axutil_env_t * env); + +axis2_status_t AXIS2_CALL +axis2_libxml2_writer_wrapper_write_attribute( + axiom_xml_writer_t * writer, + const axutil_env_t * env, + axis2_char_t * localname, + axis2_char_t * value); + +axis2_status_t AXIS2_CALL +axis2_libxml2_writer_wrapper_write_attribute_with_namespace( + axiom_xml_writer_t * writer, + const axutil_env_t * env, + axis2_char_t * localname, + axis2_char_t * value, + axis2_char_t * namespace_uri); + +axis2_status_t AXIS2_CALL +axis2_libxml2_writer_wrapper_write_attribute_with_namespace_prefix( + axiom_xml_writer_t * writer, + const axutil_env_t * env, + axis2_char_t * localname, + axis2_char_t * value, + axis2_char_t * namespace_uri, + axis2_char_t * prefix); + +axis2_status_t AXIS2_CALL +axis2_libxml2_writer_wrapper_write_namespace( + axiom_xml_writer_t * writer, + const axutil_env_t * env, + axis2_char_t * prefix, + axis2_char_t * namespace_uri); + +axis2_status_t AXIS2_CALL +axis2_libxml2_writer_wrapper_write_default_namespace( + axiom_xml_writer_t * writer, + const axutil_env_t * env, + axis2_char_t * namespace_uri); + +axis2_status_t AXIS2_CALL +axis2_libxml2_writer_wrapper_write_comment( + axiom_xml_writer_t * writer, + const axutil_env_t * env, + axis2_char_t * value); + +axis2_status_t AXIS2_CALL +axis2_libxml2_writer_wrapper_write_processing_instruction( + axiom_xml_writer_t * writer, + const axutil_env_t * env, + axis2_char_t * target); + +axis2_status_t AXIS2_CALL +axis2_libxml2_writer_wrapper_write_processing_instruction_data( + axiom_xml_writer_t * writer, + const axutil_env_t * env, + axis2_char_t * target, + axis2_char_t * data); + +axis2_status_t AXIS2_CALL +axis2_libxml2_writer_wrapper_write_cdata( + axiom_xml_writer_t * writer, + const axutil_env_t * env, + axis2_char_t * data); + +axis2_status_t AXIS2_CALL +axis2_libxml2_writer_wrapper_write_dtd( + axiom_xml_writer_t * writer, + const axutil_env_t * env, + axis2_char_t * dtd); + +axis2_status_t AXIS2_CALL +axis2_libxml2_writer_wrapper_write_entity_ref( + axiom_xml_writer_t * writer, + const axutil_env_t * env, + axis2_char_t * name); + +axis2_status_t AXIS2_CALL +axis2_libxml2_writer_wrapper_write_start_document( + axiom_xml_writer_t * writer, + const axutil_env_t * env); + +axis2_status_t AXIS2_CALL +axis2_libxml2_writer_wrapper_write_start_document_with_version( + axiom_xml_writer_t * writer, + const axutil_env_t * env, + axis2_char_t * version); + +axis2_status_t AXIS2_CALL +axis2_libxml2_writer_wrapper_write_start_document_with_version_encoding( + axiom_xml_writer_t * writer, + const axutil_env_t * env, + axis2_char_t * encoding, + axis2_char_t * version); + +axis2_status_t AXIS2_CALL +axis2_libxml2_writer_wrapper_write_characters( + axiom_xml_writer_t * writer, + const axutil_env_t * env, + axis2_char_t * text); + +axis2_char_t *AXIS2_CALL axis2_libxml2_writer_wrapper_get_prefix( + axiom_xml_writer_t * writer, + const axutil_env_t * env, + axis2_char_t * uri); + +axis2_status_t AXIS2_CALL +axis2_libxml2_writer_wrapper_set_prefix( + axiom_xml_writer_t * writer, + const axutil_env_t * env, + axis2_char_t * prefix, + axis2_char_t * uri); + +axis2_status_t AXIS2_CALL +axis2_libxml2_writer_wrapper_set_default_prefix( + axiom_xml_writer_t * writer, + const axutil_env_t * env, + axis2_char_t * uri); + +axis2_status_t AXIS2_CALL +axis2_libxml2_writer_wrapper_write_encoded( + axiom_xml_writer_t * writer, + const axutil_env_t * env, + axis2_char_t * text, + int in_attr); + +void *AXIS2_CALL axis2_libxml2_writer_wrapper_get_xml( + axiom_xml_writer_t * writer, + const axutil_env_t * env); + +unsigned int AXIS2_CALL axis2_libxml2_writer_wrapper_get_xml_size( + axiom_xml_writer_t * writer, + const axutil_env_t * env); + +axis2_status_t AXIS2_CALL +axis2_libxml2_writer_wrapper_flush( + axiom_xml_writer_t * writer, + const axutil_env_t * env); + +int AXIS2_CALL axis2_libxml2_writer_wrapper_get_type( + axiom_xml_writer_t * writer, + const axutil_env_t * env); + +axis2_status_t AXIS2_CALL +axis2_libxml2_writer_wrapper_write_raw( + axiom_xml_writer_t * writer, + const axutil_env_t * env, + axis2_char_t * content); + +static axis2_status_t +axis2_libxml2_writer_wrapper_push( + axiom_xml_writer_t * writer, + const axutil_env_t * env, + const axis2_char_t * uri, + const axis2_char_t * prefix); + +static axis2_bool_t +axis2_libxml2_writer_wrapper_is_namespace_declared( + axiom_xml_writer_t * writer, + const axutil_env_t * env, + axis2_char_t * key); + +static void +uri_prefix_element_free( + uri_prefix_element_t * up_element, + const axutil_env_t * env); + +static uri_prefix_element_t * +uri_prefix_element_create( + const axutil_env_t * env, + const axis2_char_t * uri, + const axis2_char_t * prefix, + const axis2_char_t * real_prefix, + const axis2_char_t * key); + +static void +create_key_from_uri_prefix( + const axutil_env_t * env, + const axis2_char_t * uri, + const axis2_char_t * prefix, + axis2_char_t * array); + +static axis2_char_t * +axis2_libxml2_writer_wrapper_find_prefix( + axiom_xml_writer_t * writer, + const axutil_env_t * env, + axis2_char_t * uri); + +static uri_prefix_element_t * +axis2_libxml2_writer_wrapper_find_prefix_in_context( + axutil_array_list_t * context, + const axutil_env_t * env, + axis2_char_t * uri); + +static const axiom_xml_writer_ops_t axiom_xml_writer_ops_var = { axis2_libxml2_writer_wrapper_free, + axis2_libxml2_writer_wrapper_write_start_element, + axis2_libxml2_writer_wrapper_end_start_element, + axis2_libxml2_writer_wrapper_write_start_element_with_namespace, + axis2_libxml2_writer_wrapper_write_start_element_with_namespace_prefix, + axis2_libxml2_writer_wrapper_write_empty_element, + axis2_libxml2_writer_wrapper_write_empty_element_with_namespace, + axis2_libxml2_writer_wrapper_write_empty_element_with_namespace_prefix, + axis2_libxml2_writer_wrapper_write_end_element, + axis2_libxml2_writer_wrapper_write_end_document, axis2_libxml2_writer_wrapper_write_attribute, + axis2_libxml2_writer_wrapper_write_attribute_with_namespace, + axis2_libxml2_writer_wrapper_write_attribute_with_namespace_prefix, + axis2_libxml2_writer_wrapper_write_namespace, + axis2_libxml2_writer_wrapper_write_default_namespace, + axis2_libxml2_writer_wrapper_write_comment, + axis2_libxml2_writer_wrapper_write_processing_instruction, + axis2_libxml2_writer_wrapper_write_processing_instruction_data, + axis2_libxml2_writer_wrapper_write_cdata, axis2_libxml2_writer_wrapper_write_dtd, + axis2_libxml2_writer_wrapper_write_entity_ref, + axis2_libxml2_writer_wrapper_write_start_document, + axis2_libxml2_writer_wrapper_write_start_document_with_version, + axis2_libxml2_writer_wrapper_write_start_document_with_version_encoding, + axis2_libxml2_writer_wrapper_write_characters, axis2_libxml2_writer_wrapper_get_prefix, + axis2_libxml2_writer_wrapper_set_prefix, axis2_libxml2_writer_wrapper_set_default_prefix, + axis2_libxml2_writer_wrapper_write_encoded, axis2_libxml2_writer_wrapper_get_xml, + axis2_libxml2_writer_wrapper_get_xml_size, axis2_libxml2_writer_wrapper_get_type, + axis2_libxml2_writer_wrapper_write_raw, axis2_libxml2_writer_wrapper_flush }; + +AXIS2_EXTERN axiom_xml_writer_t *AXIS2_CALL +axiom_xml_writer_create( + const axutil_env_t * env, + axis2_char_t * filename, + axis2_char_t * encoding, + int is_prefix_default, + int compression) +{ + axis2_libxml2_writer_wrapper_impl_t *writer_impl = NULL; + AXIS2_ENV_CHECK(env, NULL); + writer_impl = (axis2_libxml2_writer_wrapper_impl_t *)AXIS2_MALLOC(env->allocator, + sizeof(axis2_libxml2_writer_wrapper_impl_t)); + if(!writer_impl) + { + AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE); + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "No memory. Cannot create an XML writer wrapper"); + return NULL; + } + writer_impl->xml_writer = xmlNewTextWriterFilename(filename, compression); + + if(!(writer_impl->xml_writer)) + { + AXIS2_FREE(env->allocator, writer_impl); + AXIS2_HANDLE_ERROR(env, AXIS2_ERROR_CREATING_XML_STREAM_WRITER, AXIS2_FAILURE); + return NULL; + } + writer_impl->buffer = NULL; + writer_impl->encoding = NULL; + writer_impl->compression = 0; + writer_impl->in_empty_element = AXIS2_FALSE; + writer_impl->in_start_element = AXIS2_FALSE; + writer_impl->stack = NULL; + writer_impl->uri_prefix_map = NULL; + writer_impl->default_lang_namespace = NULL; + + writer_impl->writer_type = AXIS2_XML_PARSER_TYPE_FILE; + writer_impl->compression = compression; + + if(encoding) + { + writer_impl->encoding = axutil_strdup(env, encoding); + } + else + { + writer_impl->encoding = axutil_strdup(env, ENCODING); + } + + writer_impl->uri_prefix_map = axutil_hash_make(env); + if(!(writer_impl->uri_prefix_map)) + { + axis2_libxml2_writer_wrapper_free(&(writer_impl->writer), env); + AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE); + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "No memory. Cannot create URI prefix hash map"); + return NULL; + } + writer_impl->writer.ops = &axiom_xml_writer_ops_var; + return &(writer_impl->writer); +} + +AXIS2_EXTERN axiom_xml_writer_t *AXIS2_CALL +axiom_xml_writer_create_for_memory( + const axutil_env_t * env, + axis2_char_t * encoding, + int is_prefix_default, + int compression, + int type) +{ + axis2_libxml2_writer_wrapper_impl_t *writer_impl = NULL; + AXIS2_ENV_CHECK(env, NULL); + writer_impl = (axis2_libxml2_writer_wrapper_impl_t *)AXIS2_MALLOC(env->allocator, + sizeof(axis2_libxml2_writer_wrapper_impl_t)); + if(!writer_impl) + { + AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE); + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "No memory. Cannot create writer wrapper"); + return NULL; + } + + writer_impl->encoding = NULL; + writer_impl->buffer = NULL; + writer_impl->doc = NULL; + writer_impl->in_empty_element = AXIS2_FALSE; + writer_impl->in_start_element = AXIS2_FALSE; + writer_impl->stack = NULL; + writer_impl->uri_prefix_map = NULL; + writer_impl->default_lang_namespace = NULL; + writer_impl->compression = compression; + + if(AXIS2_XML_PARSER_TYPE_BUFFER == type) + { + writer_impl->writer_type = AXIS2_XML_PARSER_TYPE_BUFFER; + writer_impl->buffer = xmlBufferCreate(); + if(!(writer_impl->buffer)) + { + axis2_libxml2_writer_wrapper_free(&(writer_impl->writer), env); + AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE); + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, + "No memory. Cannot create a buffer for writer wrapper"); + return NULL; + } + + writer_impl->xml_writer = xmlNewTextWriterMemory(writer_impl->buffer, 0); + } + else if(AXIS2_XML_PARSER_TYPE_DOC == type) + { + writer_impl->writer_type = AXIS2_XML_PARSER_TYPE_DOC; + writer_impl->xml_writer = xmlNewTextWriterDoc(&writer_impl->doc, 0); + } + else + { + axis2_libxml2_writer_wrapper_free(&(writer_impl->writer), env); + AXIS2_HANDLE_ERROR(env, AXIS2_ERROR_XML_PARSER_INVALID_MEM_TYPE, AXIS2_FAILURE); + return NULL; + } + + if(!(writer_impl->xml_writer)) + { + axis2_libxml2_writer_wrapper_free(&(writer_impl->writer), env); + AXIS2_HANDLE_ERROR(env, AXIS2_ERROR_CREATING_XML_STREAM_WRITER, AXIS2_FAILURE); + return NULL; + } + + if(encoding) + { + writer_impl->encoding = axutil_strdup(env, encoding); + } + else + { + writer_impl->encoding = axutil_strdup(env, ENCODING); + } + + writer_impl->uri_prefix_map = axutil_hash_make(env); + if(!(writer_impl->uri_prefix_map)) + { + axis2_libxml2_writer_wrapper_free(&(writer_impl->writer), env); + AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE); + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "No memory. Cannot create URI prefix hash map"); + return NULL; + } + writer_impl->stack = axutil_stack_create(env); + if(!(writer_impl->stack)) + { + axis2_libxml2_writer_wrapper_free(&(writer_impl->writer), env); + AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE); + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, + "No memory. Cannot create the stack for writer wrapper"); + return NULL; + } + + writer_impl->writer.ops = &axiom_xml_writer_ops_var; + + return &(writer_impl->writer); +} + +void AXIS2_CALL +axis2_libxml2_writer_wrapper_free( + axiom_xml_writer_t * writer, + const axutil_env_t * env) +{ + axis2_libxml2_writer_wrapper_impl_t *writer_impl = NULL; + AXIS2_ENV_CHECK(env, AXIS2_FAILURE); + writer_impl = AXIS2_INTF_TO_IMPL(writer); + + if(writer_impl->xml_writer) + { + xmlFreeTextWriter(writer_impl->xml_writer); + writer_impl->xml_writer = NULL; + } + if(writer_impl->buffer) + { + xmlBufferFree(writer_impl->buffer); + writer_impl->buffer = NULL; + } + if(writer_impl->encoding) + { + AXIS2_FREE(env->allocator, writer_impl->encoding); + writer_impl->encoding = NULL; + } + if(writer_impl->uri_prefix_map) + { + axutil_hash_free(writer_impl->uri_prefix_map, env); + writer_impl->uri_prefix_map = NULL; + } + if(writer_impl->stack) + { + axutil_stack_free(writer_impl->stack, env); + writer_impl->stack = NULL; + } + if(writer_impl->default_lang_namespace) + { + uri_prefix_element_free(writer_impl->default_lang_namespace, env); + writer_impl->default_lang_namespace = NULL; + } + + AXIS2_FREE(env->allocator, writer_impl); + writer_impl = NULL; + return; +} + +axis2_status_t AXIS2_CALL +axis2_libxml2_writer_wrapper_write_start_element( + axiom_xml_writer_t * writer, + const axutil_env_t * env, + axis2_char_t * localname) +{ + int status = 0; + axis2_libxml2_writer_wrapper_impl_t *writer_impl = NULL; + AXIS2_ENV_CHECK(env, AXIS2_FAILURE); + AXIS2_PARAM_CHECK(env->error, localname, AXIS2_FAILURE); + writer_impl = AXIS2_INTF_TO_IMPL(writer); + + writer_impl->in_start_element = AXIS2_TRUE; + + status = xmlTextWriterStartElement(writer_impl->xml_writer, (xmlChar *)localname); + if(status < 0) + { + AXIS2_HANDLE_ERROR(env, AXIS2_ERROR_WRITING_START_ELEMENT, AXIS2_FAILURE); + return AXIS2_FAILURE; + } + return AXIS2_SUCCESS; +} + +axis2_status_t AXIS2_CALL +axis2_libxml2_writer_wrapper_end_start_element( + axiom_xml_writer_t * writer, + const axutil_env_t * env) +{ + AXIS2_ENV_CHECK(env, AXIS2_FAILURE); + /* nothing to do , + it is automatically taken care by the libxml2 writer */ + return AXIS2_SUCCESS; +} + +axis2_status_t AXIS2_CALL +axis2_libxml2_writer_wrapper_write_start_element_with_namespace( + axiom_xml_writer_t * writer, + const axutil_env_t * env, + axis2_char_t * localname, + axis2_char_t * namespace_uri) +{ + axis2_libxml2_writer_wrapper_impl_t *writer_impl = NULL; + int status = 0; + AXIS2_ENV_CHECK(env, AXIS2_FAILURE); + AXIS2_PARAM_CHECK(env->error, localname, AXIS2_FAILURE); + AXIS2_PARAM_CHECK(env->error, namespace_uri, AXIS2_FAILURE); + + writer_impl = AXIS2_INTF_TO_IMPL(writer); + + status = xmlTextWriterStartElementNS(writer_impl->xml_writer, + NULL, BAD_CAST localname, NULL); + + if(status < 0) + { + AXIS2_HANDLE_ERROR(env, AXIS2_ERROR_WRITING_START_ELEMENT_WITH_NAMESPACE, AXIS2_FAILURE); + return AXIS2_FAILURE; + } + return AXIS2_SUCCESS; +} + +axis2_status_t AXIS2_CALL +axis2_libxml2_writer_wrapper_write_start_element_with_namespace_prefix( + axiom_xml_writer_t * writer, + const axutil_env_t * env, + axis2_char_t * localname, + axis2_char_t * namespace_uri, + axis2_char_t * prefix) +{ + axis2_libxml2_writer_wrapper_impl_t *writer_impl = NULL; + int status = 0; + AXIS2_ENV_CHECK(env, AXIS2_FAILURE); + AXIS2_PARAM_CHECK(env->error, localname, AXIS2_FAILURE); + AXIS2_PARAM_CHECK(env->error, namespace_uri, AXIS2_FAILURE); + AXIS2_PARAM_CHECK(env->error, prefix, AXIS2_FAILURE); + + writer_impl = AXIS2_INTF_TO_IMPL(writer); + writer_impl->in_start_element = AXIS2_TRUE; + + status = xmlTextWriterStartElementNS(writer_impl->xml_writer, + BAD_CAST prefix, + BAD_CAST localname, BAD_CAST NULL); + if(status < 0) + { + AXIS2_HANDLE_ERROR(env, AXIS2_ERROR_WRITING_START_ELEMENT_WITH_NAMESPACE_PREFIX, + AXIS2_FAILURE); + return AXIS2_FAILURE; + } + return AXIS2_SUCCESS; +} + +axis2_status_t AXIS2_CALL +axis2_libxml2_writer_wrapper_write_empty_element( + axiom_xml_writer_t * writer, + const axutil_env_t * env, + axis2_char_t * localname) +{ + int status = 0; + axis2_libxml2_writer_wrapper_impl_t *writer_impl = NULL; + AXIS2_ENV_CHECK(env, AXIS2_FAILURE); + AXIS2_PARAM_CHECK(env->error, localname, AXIS2_FAILURE); + writer_impl = AXIS2_INTF_TO_IMPL(writer); + + status = xmlTextWriterStartElement(writer_impl->xml_writer, (xmlChar *)localname); + + if(status < 0) + { + AXIS2_HANDLE_ERROR(env, AXIS2_ERROR_WRITING_EMPTY_ELEMENT, AXIS2_FAILURE); + return AXIS2_FAILURE; + } + status = xmlTextWriterEndElement(writer_impl->xml_writer); + if(status < 0) + { + AXIS2_HANDLE_ERROR(env, AXIS2_ERROR_WRITING_EMPTY_ELEMENT, AXIS2_FAILURE); + return AXIS2_FAILURE; + } + return AXIS2_SUCCESS; +} + +axis2_status_t AXIS2_CALL +axis2_libxml2_writer_wrapper_write_empty_element_with_namespace( + axiom_xml_writer_t * writer, + const axutil_env_t * env, + axis2_char_t * localname, + axis2_char_t * namespace_uri) +{ + axis2_libxml2_writer_wrapper_impl_t *writer_impl = NULL; + int status = 0; + AXIS2_ENV_CHECK(env, AXIS2_FAILURE); + AXIS2_PARAM_CHECK(env->error, localname, AXIS2_FAILURE); + AXIS2_PARAM_CHECK(env->error, namespace_uri, AXIS2_FAILURE); + + writer_impl = AXIS2_INTF_TO_IMPL(writer); + + status = xmlTextWriterStartElementNS(writer_impl->xml_writer, + NULL, BAD_CAST localname, + BAD_CAST namespace_uri); + + if(status < 0) + { + AXIS2_HANDLE_ERROR(env, AXIS2_ERROR_WRITING_EMPTY_ELEMENT_WITH_NAMESPACE, AXIS2_FAILURE); + return AXIS2_FAILURE; + } + status = xmlTextWriterEndElement(writer_impl->xml_writer); + if(status < 0) + { + AXIS2_HANDLE_ERROR(env, AXIS2_ERROR_WRITING_EMPTY_ELEMENT_WITH_NAMESPACE, AXIS2_FAILURE); + return AXIS2_FAILURE; + } + + return AXIS2_SUCCESS; +} + +axis2_status_t AXIS2_CALL +axis2_libxml2_writer_wrapper_write_empty_element_with_namespace_prefix( + axiom_xml_writer_t * writer, + const axutil_env_t * env, + axis2_char_t * localname, + axis2_char_t * namespace_uri, + axis2_char_t * prefix) +{ + axis2_libxml2_writer_wrapper_impl_t *writer_impl = NULL; + int status = 0; + AXIS2_ENV_CHECK(env, AXIS2_FAILURE); + AXIS2_PARAM_CHECK(env->error, localname, AXIS2_FAILURE); + AXIS2_PARAM_CHECK(env->error, namespace_uri, AXIS2_FAILURE); + AXIS2_PARAM_CHECK(env->error, prefix, AXIS2_FAILURE); + + writer_impl = AXIS2_INTF_TO_IMPL(writer); + + status = xmlTextWriterStartElementNS(writer_impl->xml_writer, + BAD_CAST prefix, + BAD_CAST localname, BAD_CAST NULL); + if(status < 0) + { + AXIS2_HANDLE_ERROR(env, AXIS2_ERROR_WRITING_START_ELEMENT_WITH_NAMESPACE_PREFIX, + AXIS2_FAILURE); + return AXIS2_FAILURE; + } + status = xmlTextWriterEndElement(writer_impl->xml_writer); + if(status < 0) + { + AXIS2_HANDLE_ERROR(env, AXIS2_ERROR_WRITING_EMPTY_ELEMENT_WITH_NAMESPACE_PREFIX, + AXIS2_FAILURE); + return AXIS2_FAILURE; + } + return AXIS2_SUCCESS; +} + +axis2_status_t AXIS2_CALL +axis2_libxml2_writer_wrapper_write_end_element( + axiom_xml_writer_t * writer, + const axutil_env_t * env) +{ + axis2_libxml2_writer_wrapper_impl_t *writer_impl = NULL; + int status = 0; + + AXIS2_ENV_CHECK(env, AXIS2_FAILURE); + + writer_impl = AXIS2_INTF_TO_IMPL(writer); + + writer_impl->in_start_element = AXIS2_FALSE; + /* write an empty element in case the element is empty, + status = xmlTextWriterFullEndElement(writer_impl->xml_writer); + Above call write it like <a></a>. + Call below will write it like <a/> */ + status = xmlTextWriterEndElement(writer_impl->xml_writer); + if(status < 0) + { + AXIS2_HANDLE_ERROR(env, AXIS2_ERROR_WRITING_END_ELEMENT, AXIS2_FAILURE); + return AXIS2_FAILURE; + } + return AXIS2_SUCCESS; +} + +axis2_status_t AXIS2_CALL +axis2_libxml2_writer_wrapper_write_end_document( + axiom_xml_writer_t * writer, + const axutil_env_t * env) +{ + axis2_libxml2_writer_wrapper_impl_t *writer_impl = NULL; + int status = 0; + AXIS2_ENV_CHECK(env, AXIS2_FAILURE); + + writer_impl = AXIS2_INTF_TO_IMPL(writer); + status = xmlTextWriterEndDocument(writer_impl->xml_writer); + if(status < 0) + { + AXIS2_HANDLE_ERROR(env, AXIS2_ERROR_WRITING_END_DOCUMENT, AXIS2_FAILURE); + return AXIS2_FAILURE; + } + return AXIS2_SUCCESS; +} + +axis2_status_t AXIS2_CALL +axis2_libxml2_writer_wrapper_write_attribute( + axiom_xml_writer_t * writer, + const axutil_env_t * env, + axis2_char_t * localname, + axis2_char_t * value) +{ + axis2_libxml2_writer_wrapper_impl_t *writer_impl = NULL; + int status = 0; + AXIS2_ENV_CHECK(env, AXIS2_FAILURE); + AXIS2_PARAM_CHECK(env->error, localname, AXIS2_FAILURE); + if(!value) + { + value = ""; + } + + writer_impl = AXIS2_INTF_TO_IMPL(writer); + status = xmlTextWriterWriteAttribute(writer_impl->xml_writer, + BAD_CAST localname, BAD_CAST value); + if(status < 0) + { + AXIS2_HANDLE_ERROR(env, AXIS2_ERROR_WRITING_ATTRIBUTE, AXIS2_FAILURE); + return AXIS2_FAILURE; + } + return AXIS2_SUCCESS; +} + +axis2_status_t AXIS2_CALL +axis2_libxml2_writer_wrapper_write_attribute_with_namespace( + axiom_xml_writer_t * writer, + const axutil_env_t * env, + axis2_char_t * localname, + axis2_char_t * value, + axis2_char_t * namespace_uri) +{ + axis2_libxml2_writer_wrapper_impl_t *writer_impl = NULL; + int status = 0; + AXIS2_ENV_CHECK(env, AXIS2_FAILURE); + AXIS2_PARAM_CHECK(env->error, localname, AXIS2_FAILURE); + AXIS2_PARAM_CHECK(env->error, namespace_uri, AXIS2_FAILURE); + + if(!value) + { + value = ""; + } + + writer_impl = AXIS2_INTF_TO_IMPL(writer); + status = xmlTextWriterWriteAttributeNS(writer_impl->xml_writer, + NULL, BAD_CAST localname, + BAD_CAST NULL, BAD_CAST value); + if(status < 0) + { + AXIS2_HANDLE_ERROR(env, AXIS2_ERROR_WRITING_ATTRIBUTE_WITH_NAMESPACE, AXIS2_FAILURE); + return AXIS2_FAILURE; + } + return AXIS2_SUCCESS; +} + +axis2_status_t AXIS2_CALL +axis2_libxml2_writer_wrapper_write_attribute_with_namespace_prefix( + axiom_xml_writer_t * writer, + const axutil_env_t * env, + axis2_char_t * localname, + axis2_char_t * value, + axis2_char_t * namespace_uri, + axis2_char_t * prefix) +{ + axis2_libxml2_writer_wrapper_impl_t *writer_impl = NULL; + int status = 0; + AXIS2_ENV_CHECK(env, AXIS2_FAILURE); + AXIS2_PARAM_CHECK(env->error, localname, AXIS2_FAILURE); + AXIS2_PARAM_CHECK(env->error, namespace_uri, AXIS2_FAILURE); + AXIS2_PARAM_CHECK(env->error, prefix, AXIS2_FAILURE); + + if(!value) + { + value = ""; + } + writer_impl = AXIS2_INTF_TO_IMPL(writer); + status = xmlTextWriterWriteAttributeNS(writer_impl->xml_writer, + BAD_CAST prefix, BAD_CAST localname, + BAD_CAST NULL, BAD_CAST value); + if(status < 0) + { + AXIS2_HANDLE_ERROR(env, AXIS2_ERROR_WRITING_ATTRIBUTE_WITH_NAMESPACE_PREFIX, AXIS2_FAILURE); + return AXIS2_FAILURE; + } + return AXIS2_SUCCESS; +} + +/** need to work on this */ +axis2_status_t AXIS2_CALL +axis2_libxml2_writer_wrapper_write_namespace( + axiom_xml_writer_t * writer, + const axutil_env_t * env, + axis2_char_t * prefix, + axis2_char_t * namespace_uri) +{ + axis2_libxml2_writer_wrapper_impl_t *writer_impl = NULL; + int status = 0; + char *xmlnsprefix = NULL; + + AXIS2_ENV_CHECK(env, AXIS2_FAILURE); + AXIS2_PARAM_CHECK(env->error, namespace_uri, AXIS2_FAILURE); + + writer_impl = AXIS2_INTF_TO_IMPL(writer); + + if(prefix && (axutil_strcmp(prefix, "") != 0)) + { + xmlnsprefix = (axis2_char_t *)AXIS2_MALLOC(env->allocator, (sizeof(char) * (axutil_strlen( + prefix) + 7))); + sprintf(xmlnsprefix, "xmlns:%s", prefix); + } + else + { + xmlnsprefix = axutil_strdup(env, "xmlns"); + } + + status = xmlTextWriterWriteAttribute(writer_impl->xml_writer, + BAD_CAST xmlnsprefix, + BAD_CAST namespace_uri); + AXIS2_FREE(env->allocator, xmlnsprefix); + xmlnsprefix = NULL; + + if(status < 0) + { + AXIS2_HANDLE_ERROR(env, AXIS2_ERROR_WRITING_ATTRIBUTE_WITH_NAMESPACE_PREFIX, AXIS2_FAILURE); + return AXIS2_FAILURE; + } + + AXIS2_FREE(env->allocator, xmlnsprefix); + xmlnsprefix = NULL; + return AXIS2_SUCCESS; +} + +axis2_status_t AXIS2_CALL +axis2_libxml2_writer_wrapper_write_default_namespace( + axiom_xml_writer_t * writer, + const axutil_env_t * env, + axis2_char_t * namespace_uri) +{ + axis2_libxml2_writer_wrapper_impl_t *writer_impl = NULL; + int status = 0; + axis2_char_t *xmlns = NULL; + AXIS2_ENV_CHECK(env, AXIS2_FAILURE); + AXIS2_PARAM_CHECK(env->error, namespace_uri, AXIS2_FAILURE) + xmlns = AXIS2_MALLOC(env->allocator, + sizeof(axis2_char_t) * (strlen("xmlns") + 1)); + sprintf(xmlns, "xmlns"); + status = xmlTextWriterWriteAttribute(writer_impl->xml_writer, + (const xmlChar *) xmlns, + BAD_CAST namespace_uri); + + if(xmlns) + { + AXIS2_FREE(env->allocator, xmlns); + xmlns = NULL; + } + if(status < 0) + { + AXIS2_HANDLE_ERROR(env, AXIS2_ERROR_WRITING_DEFAULT_NAMESPACE, AXIS2_FAILURE); + return AXIS2_FAILURE; + } + return AXIS2_SUCCESS; +} + +axis2_status_t AXIS2_CALL +axis2_libxml2_writer_wrapper_write_comment( + axiom_xml_writer_t * writer, + const axutil_env_t * env, + axis2_char_t * value) +{ + axis2_libxml2_writer_wrapper_impl_t *writer_impl = NULL; + int status = 0; + AXIS2_ENV_CHECK(env, AXIS2_FAILURE); + AXIS2_PARAM_CHECK(env->error, value, AXIS2_FAILURE); + + writer_impl = AXIS2_INTF_TO_IMPL(writer); + status = xmlTextWriterWriteComment(writer_impl->xml_writer, BAD_CAST value); + if(status < 0) + { + AXIS2_HANDLE_ERROR(env, AXIS2_ERROR_WRITING_COMMENT, AXIS2_FAILURE); + return AXIS2_FAILURE; + } + return AXIS2_SUCCESS; +} + +axis2_status_t AXIS2_CALL +axis2_libxml2_writer_wrapper_write_processing_instruction( + axiom_xml_writer_t * writer, + const axutil_env_t * env, + axis2_char_t * target) +{ + axis2_libxml2_writer_wrapper_impl_t *writer_impl = NULL; + int status = 0; + AXIS2_ENV_CHECK(env, AXIS2_FAILURE); + AXIS2_PARAM_CHECK(env->error, target, AXIS2_FAILURE); + writer_impl = AXIS2_INTF_TO_IMPL(writer); + + status = xmlTextWriterStartPI(writer_impl->xml_writer, BAD_CAST target); + if(status < 0) + { + AXIS2_HANDLE_ERROR(env, AXIS2_ERROR_WRITING_PROCESSING_INSTRUCTION, AXIS2_FAILURE); + return AXIS2_FAILURE; + } + return AXIS2_SUCCESS; +} + +axis2_status_t AXIS2_CALL +axis2_libxml2_writer_wrapper_write_processing_instruction_data( + axiom_xml_writer_t * writer, + const axutil_env_t * env, + axis2_char_t * target, + axis2_char_t * data) +{ + axis2_libxml2_writer_wrapper_impl_t *writer_impl = NULL; + int status = 0; + AXIS2_ENV_CHECK(env, AXIS2_FAILURE); + AXIS2_PARAM_CHECK(env->error, target, AXIS2_FAILURE); + AXIS2_PARAM_CHECK(env->error, data, AXIS2_FAILURE); + writer_impl = AXIS2_INTF_TO_IMPL(writer); + + status = xmlTextWriterWritePI(writer_impl->xml_writer, + BAD_CAST target, BAD_CAST data); + if(status < 0) + { + AXIS2_HANDLE_ERROR(env, AXIS2_ERROR_WRITING_PROCESSING_INSTRUCTION, AXIS2_FAILURE); + return AXIS2_FAILURE; + } + return AXIS2_SUCCESS; +} + +axis2_status_t AXIS2_CALL +axis2_libxml2_writer_wrapper_write_cdata( + axiom_xml_writer_t * writer, + const axutil_env_t * env, + axis2_char_t * data) +{ + axis2_libxml2_writer_wrapper_impl_t *writer_impl = NULL; + int status = 0; + AXIS2_ENV_CHECK(env, AXIS2_FAILURE); + AXIS2_PARAM_CHECK(env->error, data, AXIS2_FAILURE); + + writer_impl = AXIS2_INTF_TO_IMPL(writer); + + status = xmlTextWriterWriteCDATA(writer_impl->xml_writer, BAD_CAST data); + if(status < 0) + { + AXIS2_HANDLE_ERROR(env, AXIS2_ERROR_WRITING_CDATA, AXIS2_FAILURE); + return AXIS2_FAILURE; + } + return AXIS2_SUCCESS; +} + +axis2_status_t AXIS2_CALL +axis2_libxml2_writer_wrapper_write_dtd( + axiom_xml_writer_t * writer, + const axutil_env_t * env, + axis2_char_t * dtd) +{ + axis2_libxml2_writer_wrapper_impl_t *writer_impl = NULL; + int status = 0; + AXIS2_ENV_CHECK(env, AXIS2_FAILURE); + AXIS2_PARAM_CHECK(env->error, dtd, AXIS2_FAILURE); + + status = xmlTextWriterStartDTD(writer_impl->xml_writer, + BAD_CAST dtd, NULL, NULL); + if(status < 0) + { + AXIS2_HANDLE_ERROR(env, AXIS2_ERROR_WRITING_DTD, AXIS2_FAILURE); + return AXIS2_FAILURE; + } + return AXIS2_SUCCESS; +} + +axis2_status_t AXIS2_CALL +axis2_libxml2_writer_wrapper_write_entity_ref( + axiom_xml_writer_t * writer, + const axutil_env_t * env, + axis2_char_t * name) +{ + AXIS2_ENV_CHECK(env, AXIS2_FAILURE); + AXIS2_PARAM_CHECK(env->error, name, AXIS2_FAILURE); + return AXIS2_FAILURE; +} + +axis2_status_t AXIS2_CALL +axis2_libxml2_writer_wrapper_write_start_document( + axiom_xml_writer_t * writer, + const axutil_env_t * env) +{ + axis2_libxml2_writer_wrapper_impl_t *wrapper_impl = NULL; + int status = 0; + AXIS2_ENV_CHECK(env, AXIS2_FAILURE); + + wrapper_impl = AXIS2_INTF_TO_IMPL(writer); + status = xmlTextWriterStartDocument(wrapper_impl->xml_writer, NULL, NULL, NULL); + if(status < 0) + { + AXIS2_HANDLE_ERROR(env, AXIS2_ERROR_WRITING_START_DOCUMENT, AXIS2_FAILURE); + return AXIS2_FAILURE; + } + return AXIS2_SUCCESS; +} + +axis2_status_t AXIS2_CALL +axis2_libxml2_writer_wrapper_write_start_document_with_version( + axiom_xml_writer_t * writer, + const axutil_env_t * env, + axis2_char_t * version) +{ + axis2_libxml2_writer_wrapper_impl_t *wrapper_impl = NULL; + int status = 0; + AXIS2_ENV_CHECK(env, AXIS2_FAILURE); + AXIS2_PARAM_CHECK(env->error, version, AXIS2_FAILURE); + + wrapper_impl = AXIS2_INTF_TO_IMPL(writer); + status = xmlTextWriterStartDocument(wrapper_impl->xml_writer, version, NULL, NULL); + if(status < 0) + { + AXIS2_HANDLE_ERROR(env, AXIS2_ERROR_WRITING_START_DOCUMENT, AXIS2_FAILURE); + return AXIS2_FAILURE; + } + return AXIS2_SUCCESS; +} + +axis2_status_t AXIS2_CALL +axis2_libxml2_writer_wrapper_write_start_document_with_version_encoding( + axiom_xml_writer_t * writer, + const axutil_env_t * env, + axis2_char_t * encoding, + axis2_char_t * version) +{ + axis2_libxml2_writer_wrapper_impl_t *wrapper_impl = NULL; + int status = 0; + AXIS2_ENV_CHECK(env, AXIS2_FAILURE); + + wrapper_impl = AXIS2_INTF_TO_IMPL(writer); + status = xmlTextWriterStartDocument(wrapper_impl->xml_writer, version, encoding, NULL); + if(status < 0) + { + AXIS2_HANDLE_ERROR(env, AXIS2_ERROR_WRITING_START_DOCUMENT, AXIS2_FAILURE); + return AXIS2_FAILURE; + } + return AXIS2_SUCCESS; +} + +axis2_status_t AXIS2_CALL +axis2_libxml2_writer_wrapper_write_characters( + axiom_xml_writer_t * writer, + const axutil_env_t * env, + axis2_char_t * text) +{ + axis2_libxml2_writer_wrapper_impl_t *writer_impl = NULL; + int status = 0; + + AXIS2_ENV_CHECK(env, AXIS2_FAILURE); + AXIS2_PARAM_CHECK(env->error, text, AXIS2_FAILURE); + + writer_impl = AXIS2_INTF_TO_IMPL(writer); + + status = xmlTextWriterWriteString(writer_impl->xml_writer, BAD_CAST text); + if(status < 0) + { + AXIS2_HANDLE_ERROR(env, AXIS2_ERROR_WRITING_START_DOCUMENT, AXIS2_FAILURE); + return AXIS2_FAILURE; + } + return AXIS2_SUCCESS; +} + +axis2_char_t *AXIS2_CALL +axis2_libxml2_writer_wrapper_get_prefix( + axiom_xml_writer_t * writer, + const axutil_env_t * env, + axis2_char_t * uri) +{ + axis2_libxml2_writer_wrapper_impl_t *writer_impl = NULL; + AXIS2_PARAM_CHECK(env->error, uri, NULL); + writer_impl = AXIS2_INTF_TO_IMPL(writer); + if(!uri || axutil_strcmp(uri, "") == 0) + { + return NULL; + } + return axis2_libxml2_writer_wrapper_find_prefix(writer, env, uri); +} + +axis2_status_t AXIS2_CALL +axis2_libxml2_writer_wrapper_set_prefix( + axiom_xml_writer_t * writer, + const axutil_env_t * env, + axis2_char_t * prefix, + axis2_char_t * uri) +{ + axis2_libxml2_writer_wrapper_impl_t *writer_impl = NULL; + + axis2_bool_t is_declared = AXIS2_FALSE; + axis2_char_t key[1024]; + + AXIS2_ENV_CHECK(env, AXIS2_FAILURE); + AXIS2_PARAM_CHECK(env->error, prefix, AXIS2_FAILURE); + AXIS2_PARAM_CHECK(env->error, uri, AXIS2_FAILURE); + writer_impl = AXIS2_INTF_TO_IMPL(writer); + if(axutil_strcmp(uri, "") == 0) + { + return AXIS2_FAILURE; + } + + create_key_from_uri_prefix(env, uri, prefix, key); + + is_declared = axis2_libxml2_writer_wrapper_is_namespace_declared(writer, env, key); + if(!is_declared) + { + return axis2_libxml2_writer_wrapper_push(writer, env, uri, prefix); + } + return AXIS2_FAILURE; +} + +axis2_status_t AXIS2_CALL +axis2_libxml2_writer_wrapper_set_default_prefix( + axiom_xml_writer_t * writer, + const axutil_env_t * env, + axis2_char_t * uri) +{ + axis2_bool_t is_declared = AXIS2_FALSE; + + AXIS2_ENV_CHECK(env, AXIS2_FAILURE); + AXIS2_PARAM_CHECK(env->error, uri, AXIS2_FAILURE); + if(axutil_strcmp(uri, "") == 0) + { + return AXIS2_FAILURE; + } + is_declared = axis2_libxml2_writer_wrapper_is_namespace_declared(writer, env, uri); + if(!is_declared) + { + return axis2_libxml2_writer_wrapper_push(writer, env, uri, NULL); + } + return AXIS2_FAILURE; +} + +axis2_status_t AXIS2_CALL +axis2_libxml2_writer_wrapper_write_encoded( + axiom_xml_writer_t * writer, + const axutil_env_t * env, + axis2_char_t * text, + int in_attr) +{ + axis2_libxml2_writer_wrapper_impl_t *writer_impl = NULL; + AXIS2_ENV_CHECK(env, AXIS2_FAILURE); + AXIS2_PARAM_CHECK(env->error, text, AXIS2_FAILURE); + writer_impl = AXIS2_INTF_TO_IMPL(writer); + return AXIS2_FAILURE; +} + +void *AXIS2_CALL +axis2_libxml2_writer_wrapper_get_xml( + axiom_xml_writer_t * writer, + const axutil_env_t * env) +{ + axis2_libxml2_writer_wrapper_impl_t *writer_impl = NULL; + writer_impl = AXIS2_INTF_TO_IMPL(writer); + if(writer_impl->writer_type == AXIS2_XML_PARSER_TYPE_BUFFER) + { + int output_bytes = 0; + output_bytes = xmlTextWriterFlush(writer_impl->xml_writer); + return writer_impl->buffer->content; + } + else if(writer_impl->writer_type == AXIS2_XML_PARSER_TYPE_DOC) + { + return (void *)writer_impl->doc; + } + else if(writer_impl->writer_type == AXIS2_XML_PARSER_TYPE_FILE) + { + return NULL; + } + + return NULL; +} + +unsigned int AXIS2_CALL +axis2_libxml2_writer_wrapper_get_xml_size( + axiom_xml_writer_t * writer, + const axutil_env_t * env) +{ + axis2_libxml2_writer_wrapper_impl_t *writer_impl = NULL; + writer_impl = AXIS2_INTF_TO_IMPL(writer); + + if(writer_impl->writer_type == AXIS2_XML_PARSER_TYPE_BUFFER) + { + return writer_impl->buffer->use; + } + else + { + return 0; + } +} + +axis2_status_t AXIS2_CALL +axis2_libxml2_writer_wrapper_flush( + axiom_xml_writer_t * writer, + const axutil_env_t * env) +{ + axis2_libxml2_writer_wrapper_impl_t *writer_impl = NULL; + writer_impl = AXIS2_INTF_TO_IMPL(writer); + if(writer_impl->xml_writer) + { + int ret = 0; + ret = xmlTextWriterFlush(writer_impl->xml_writer); + if(ret > -1) + return AXIS2_SUCCESS; + } + + return AXIS2_FAILURE; +} + +int AXIS2_CALL +axis2_libxml2_writer_wrapper_get_type( + axiom_xml_writer_t * writer, + const axutil_env_t * env) +{ + axis2_libxml2_writer_wrapper_impl_t *writer_impl = NULL; + writer_impl = AXIS2_INTF_TO_IMPL(writer); + + return writer_impl->writer_type; +} + +static axis2_status_t +axis2_libxml2_writer_wrapper_push( + axiom_xml_writer_t * writer, + const axutil_env_t * env, + const axis2_char_t * uri, + const axis2_char_t * prefix) +{ + axis2_libxml2_writer_wrapper_impl_t *writer_impl = NULL; + axutil_array_list_t *current_list = NULL; + axis2_char_t key[1024]; + const axis2_char_t *temp_prefix = NULL; + writer_impl = AXIS2_INTF_TO_IMPL(writer); + if(!prefix || axutil_strcmp(prefix, "") == 0) + { + temp_prefix = "default"; + } + else + { + temp_prefix = prefix; + } + + if(writer_impl->stack) + { + current_list = (axutil_array_list_t *)axutil_stack_get(writer_impl->stack, env); + + if(current_list) + { + uri_prefix_element_t *ele = NULL; + create_key_from_uri_prefix(env, uri, prefix, key); + + ele = uri_prefix_element_create(env, uri, temp_prefix, prefix, key); + if(ele) + { + axutil_array_list_add(current_list, env, ele); + axutil_hash_set(writer_impl->uri_prefix_map, ele->key, AXIS2_HASH_KEY_STRING, + ele->prefix); + } + } + } + return AXIS2_SUCCESS; +} + +static axis2_bool_t +axis2_libxml2_writer_wrapper_is_namespace_declared( + axiom_xml_writer_t * writer, + const axutil_env_t * env, + axis2_char_t * key) +{ + axis2_libxml2_writer_wrapper_impl_t *writer_impl = NULL; + AXIS2_ENV_CHECK(env, AXIS2_FALSE); + writer_impl = AXIS2_INTF_TO_IMPL(writer); + if(writer_impl->uri_prefix_map && NULL != key) + { + void *ret = NULL; + ret = axutil_hash_get(writer_impl->uri_prefix_map, key, AXIS2_HASH_KEY_STRING); + if(ret) + { + return AXIS2_TRUE; + } + } + return AXIS2_FALSE; +} + +static void +uri_prefix_element_free( + uri_prefix_element_t * up_element, + const axutil_env_t * env) +{ + if(up_element) + { + if(up_element->uri) + { + AXIS2_FREE(env->allocator, up_element->uri); + up_element->uri = NULL; + } + if(up_element->prefix) + { + AXIS2_FREE(env->allocator, up_element->prefix); + up_element->prefix = NULL; + } + if(up_element->key) + { + AXIS2_FREE(env->allocator, up_element->key); + up_element->key = NULL; + } + if(up_element->real_prefix) + { + AXIS2_FREE(env->allocator, up_element->real_prefix); + up_element->real_prefix = NULL; + } + AXIS2_FREE(env->allocator, up_element); + up_element = NULL; + } + return; +} + +static uri_prefix_element_t * +uri_prefix_element_create( + const axutil_env_t * env, + const axis2_char_t * uri, + const axis2_char_t * prefix, + const axis2_char_t * real_prefix, + const axis2_char_t * key) +{ + uri_prefix_element_t *up_element = NULL; + up_element = (uri_prefix_element_t *)AXIS2_MALLOC(env->allocator, sizeof(uri_prefix_element_t)); + + if(!uri) + { + return NULL; + } + + if(!up_element) + { + AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE); + AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "No memory. Cannot create URI prefix element %s", + uri); + return NULL; + } + up_element->key = NULL; + up_element->prefix = NULL; + up_element->uri = NULL; + up_element->real_prefix = NULL; + + up_element->uri = axutil_strdup(env, uri); + if(!up_element->uri) + { + uri_prefix_element_free(up_element, env); + AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE); + return NULL; + } + up_element->prefix = axutil_strdup(env, prefix); + if(prefix && !up_element->prefix) + { + uri_prefix_element_free(up_element, env); + AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE); + return NULL; + } + up_element->key = axutil_strdup(env, key); + if(key && !up_element->key) + { + uri_prefix_element_free(up_element, env); + AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE); + return NULL; + } + up_element->real_prefix = axutil_strdup(env, real_prefix); + + return up_element; +} + +static void +create_key_from_uri_prefix( + const axutil_env_t * env, + const axis2_char_t * uri, + const axis2_char_t * prefix, + axis2_char_t * array) +{ + if(!prefix) + { + prefix = ""; + } + sprintf(array, "%s%s%s", uri, "|", prefix); +} + +static axis2_char_t * +axis2_libxml2_writer_wrapper_find_prefix( + axiom_xml_writer_t * writer, + const axutil_env_t * env, + axis2_char_t * uri) +{ + axis2_libxml2_writer_wrapper_impl_t *writer_impl = NULL; + int size = 0; + int i = 0; + + writer_impl = AXIS2_INTF_TO_IMPL(writer); + + if(!writer_impl->stack) + { + return NULL; + } + size = axutil_stack_size(writer_impl->stack, env); + if(size <= 0) + { + return NULL; + } + + for(i = size - 1; i < 0; i--) + { + axutil_array_list_t *context = NULL; + void *value = NULL; + value = axutil_stack_get_at(writer_impl->stack, env, i); + if(value) + { + uri_prefix_element_t *up_ele = NULL; + context = (axutil_array_list_t *)value; + up_ele = axis2_libxml2_writer_wrapper_find_prefix_in_context(context, env, uri); + if(up_ele) + { + return up_ele->real_prefix; + } + } + } + return NULL; +} + +static uri_prefix_element_t * +axis2_libxml2_writer_wrapper_find_prefix_in_context( + axutil_array_list_t * context, + const axutil_env_t * env, + axis2_char_t * uri) +{ + int size = 0; + int i = 0; + if(!context) + { + return NULL; + } + size = axutil_array_list_size(context, env); + for(i = 0; i < size; i++) + { + uri_prefix_element_t *ele = NULL; + void *value = NULL; + value = axutil_array_list_get(context, env, i); + if(value) + { + ele = (uri_prefix_element_t *)value; + if(ele->uri && axutil_strcmp(uri, ele->uri)) + { + return ele; + } + } + } + return NULL; +} + +axis2_status_t AXIS2_CALL +axis2_libxml2_writer_wrapper_write_raw( + axiom_xml_writer_t * writer, + const axutil_env_t * env, + axis2_char_t * content) +{ + axis2_libxml2_writer_wrapper_impl_t *writer_impl = NULL; + int status = 0; + AXIS2_ENV_CHECK(env, AXIS2_FAILURE); + AXIS2_PARAM_CHECK(env->error, content, AXIS2_FAILURE); + + writer_impl = AXIS2_INTF_TO_IMPL(writer); + status = xmlTextWriterWriteRaw(writer_impl->xml_writer, BAD_CAST content); + if(status < 0) + { + AXIS2_HANDLE_ERROR(env, AXIS2_ERROR_WRITING_DATA_SOURCE, AXIS2_FAILURE); + return AXIS2_FAILURE; + } + return AXIS2_SUCCESS; +} diff --git a/axiom/src/parser/xml_reader.c b/axiom/src/parser/xml_reader.c new file mode 100644 index 0000000..47e2334 --- /dev/null +++ b/axiom/src/parser/xml_reader.c @@ -0,0 +1,203 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + */ + +#include <axiom_xml_reader.h> + +AXIS2_EXTERN int AXIS2_CALL +axiom_xml_reader_next( + axiom_xml_reader_t * parser, + const axutil_env_t * env) +{ + return (parser)->ops->next(parser, env); +} + +AXIS2_EXTERN void AXIS2_CALL +axiom_xml_reader_free( + axiom_xml_reader_t * parser, + const axutil_env_t * env) +{ + (parser)->ops->free(parser, env); +} + +AXIS2_EXTERN int AXIS2_CALL +axiom_xml_reader_get_attribute_count( + axiom_xml_reader_t * parser, + const axutil_env_t * env) +{ + return (parser)->ops->get_attribute_count(parser, env); +} + +AXIS2_EXTERN axis2_char_t *AXIS2_CALL +axiom_xml_reader_get_attribute_name_by_number( + axiom_xml_reader_t * parser, + const axutil_env_t * env, + int i) +{ + return (parser)->ops->get_attribute_name_by_number(parser, env, i); +} + +AXIS2_EXTERN axis2_char_t *AXIS2_CALL +axiom_xml_reader_get_attribute_prefix_by_number( + axiom_xml_reader_t * parser, + const axutil_env_t * env, + int i) +{ + return (parser)->ops->get_attribute_prefix_by_number(parser, env, i); +} + +AXIS2_EXTERN axis2_char_t *AXIS2_CALL +axiom_xml_reader_get_attribute_value_by_number( + axiom_xml_reader_t * parser, + const axutil_env_t * env, + int i) +{ + return (parser)->ops->get_attribute_value_by_number(parser, env, i); +} + +AXIS2_EXTERN axis2_char_t *AXIS2_CALL +axiom_xml_reader_get_attribute_namespace_by_number( + axiom_xml_reader_t * parser, + const axutil_env_t * env, + int i) +{ + return (parser)->ops->get_attribute_namespace_by_number(parser, env, i); +} + +AXIS2_EXTERN axis2_char_t *AXIS2_CALL +axiom_xml_reader_get_value( + axiom_xml_reader_t * parser, + const axutil_env_t * env) +{ + return (parser)->ops->get_value(parser, env); +} + +AXIS2_EXTERN int AXIS2_CALL +axiom_xml_reader_get_namespace_count( + axiom_xml_reader_t * parser, + const axutil_env_t * env) +{ + return (parser)->ops->get_namespace_count(parser, env); +} + +AXIS2_EXTERN axis2_char_t *AXIS2_CALL +axiom_xml_reader_get_namespace_uri_by_number( + axiom_xml_reader_t * parser, + const axutil_env_t * env, + int i) +{ + return (parser)->ops->get_namespace_uri_by_number(parser, env, i); +} + +AXIS2_EXTERN axis2_char_t *AXIS2_CALL +axiom_xml_reader_get_namespace_prefix_by_number( + axiom_xml_reader_t * parser, + const axutil_env_t * env, + int i) +{ + return (parser)->ops->get_namespace_prefix_by_number(parser, env, i); +} + +AXIS2_EXTERN axis2_char_t *AXIS2_CALL +axiom_xml_reader_get_prefix( + axiom_xml_reader_t * parser, + const axutil_env_t * env) +{ + return (parser)->ops->get_prefix(parser, env); +} + +AXIS2_EXTERN axis2_char_t *AXIS2_CALL +axiom_xml_reader_get_name( + axiom_xml_reader_t * parser, + const axutil_env_t * env) +{ + return (parser)->ops->get_name(parser, env); +} + +AXIS2_EXTERN axis2_char_t *AXIS2_CALL +axiom_xml_reader_get_pi_target( + axiom_xml_reader_t * parser, + const axutil_env_t * env) +{ + return (parser)->ops->get_pi_target(parser, env); +} + +AXIS2_EXTERN axis2_char_t *AXIS2_CALL +axiom_xml_reader_get_pi_data( + axiom_xml_reader_t * parser, + const axutil_env_t * env) +{ + return (parser)->ops->get_pi_data(parser, env); +} + +AXIS2_EXTERN axis2_char_t *AXIS2_CALL +axiom_xml_reader_get_dtd( + axiom_xml_reader_t * parser, + const axutil_env_t * env) +{ + return (parser)->ops->get_dtd(parser, env); +} + +AXIS2_EXTERN void AXIS2_CALL +axiom_xml_reader_xml_free( + axiom_xml_reader_t * parser, + const axutil_env_t * env, + void *data) +{ + (parser)->ops->xml_free(parser, env, data); +} + +AXIS2_EXTERN axis2_char_t *AXIS2_CALL +axiom_xml_reader_get_char_set_encoding( + axiom_xml_reader_t * parser, + const axutil_env_t * env) +{ + return (parser)->ops->get_char_set_encoding(parser, env); +} + +AXIS2_EXTERN axis2_char_t *AXIS2_CALL +axiom_xml_reader_get_namespace_uri( + axiom_xml_reader_t * parser, + const axutil_env_t * env) +{ + return (parser)->ops->get_namespace_uri(parser, env); +} + +AXIS2_EXTERN axis2_char_t *AXIS2_CALL +axiom_xml_reader_get_namespace_uri_by_prefix( + axiom_xml_reader_t * parser, + const axutil_env_t * env, + axis2_char_t * prefix) +{ + return (parser)->ops->get_namespace_uri_by_prefix(parser, env, prefix); +} + +AXIS2_EXTERN void *AXIS2_CALL +axiom_xml_reader_get_context( + axiom_xml_reader_t * parser, + const axutil_env_t * env) +{ + return (parser)->ops->get_context(parser, env); +} + +AXIS2_EXTERN axis2_char_t *AXIS2_CALL +axiom_xml_reader_get_current_buffer( + axiom_xml_reader_t * parser, + const axutil_env_t * env) +{ + return (parser)->ops->get_current_buffer(parser, env); +} + diff --git a/axiom/src/parser/xml_writer.c b/axiom/src/parser/xml_writer.c new file mode 100644 index 0000000..cefaeae --- /dev/null +++ b/axiom/src/parser/xml_writer.c @@ -0,0 +1,337 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + */ + +#include <axiom_xml_writer.h> + +AXIS2_EXTERN void AXIS2_CALL +axiom_xml_writer_free( + axiom_xml_writer_t * writer, + const axutil_env_t * env) +{ + (writer)->ops->free(writer, env); +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +axiom_xml_writer_write_start_element( + axiom_xml_writer_t * writer, + const axutil_env_t * env, + axis2_char_t * localname) +{ + return (writer)->ops->write_start_element(writer, env, localname); + +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +axiom_xml_writer_end_start_element( + axiom_xml_writer_t * writer, + const axutil_env_t * env) +{ + return (writer)->ops->end_start_element(writer, env); +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +axiom_xml_writer_write_start_element_with_namespace( + axiom_xml_writer_t * writer, + const axutil_env_t * env, + axis2_char_t * localname, + axis2_char_t * namespace_uri) +{ + return (writer)->ops->write_start_element_with_namespace(writer, env, localname, namespace_uri); +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +axiom_xml_writer_write_start_element_with_namespace_prefix( + axiom_xml_writer_t * writer, + const axutil_env_t * env, + axis2_char_t * localname, + axis2_char_t * namespace_uri, + axis2_char_t * prefix) +{ + return (writer)->ops->write_start_element_with_namespace_prefix(writer, env, localname, + namespace_uri, prefix); +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +axiom_xml_writer_write_empty_element( + axiom_xml_writer_t * writer, + const axutil_env_t * env, + axis2_char_t * localname) +{ + return (writer)->ops->write_empty_element(writer, env, localname); +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +axiom_xml_writer_write_empty_element_with_namespace( + axiom_xml_writer_t * writer, + const axutil_env_t * env, + axis2_char_t * localname, + axis2_char_t * namespace_uri) +{ + return (writer)->ops->write_empty_element_with_namespace(writer, env, localname, namespace_uri); +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +axiom_xml_writer_write_empty_element_with_namespace_prefix( + axiom_xml_writer_t * writer, + const axutil_env_t * env, + axis2_char_t * localname, + axis2_char_t * namespace_uri, + axis2_char_t * prefix) +{ + return (writer)->ops->write_empty_element_with_namespace_prefix(writer, env, localname, + namespace_uri, prefix); +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +axiom_xml_writer_write_end_element( + axiom_xml_writer_t * writer, + const axutil_env_t * env) +{ + return (writer)->ops->write_end_element(writer, env); +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +axiom_xml_writer_write_end_document( + axiom_xml_writer_t * writer, + const axutil_env_t * env) +{ + return (writer)->ops->write_end_document(writer, env); +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +axiom_xml_writer_write_attribute( + axiom_xml_writer_t * writer, + const axutil_env_t * env, + axis2_char_t * localname, + axis2_char_t * value) +{ + return (writer)->ops->write_attribute(writer, env, localname, value); +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +axiom_xml_writer_write_attribute_with_namespace( + axiom_xml_writer_t * writer, + const axutil_env_t * env, + axis2_char_t * localname, + axis2_char_t * value, + axis2_char_t * namespace_uri) +{ + return (writer)->ops->write_attribute_with_namespace(writer, env, localname, value, + namespace_uri); +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +axiom_xml_writer_write_attribute_with_namespace_prefix( + axiom_xml_writer_t * writer, + const axutil_env_t * env, + axis2_char_t * localname, + axis2_char_t * value, + axis2_char_t * namespace_uri, + axis2_char_t * prefix) +{ + return (writer)->ops->write_attribute_with_namespace_prefix(writer, env, localname, value, + namespace_uri, prefix); +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +axiom_xml_writer_write_namespace( + axiom_xml_writer_t * writer, + const axutil_env_t * env, + axis2_char_t * prefix, + axis2_char_t * namespace_uri) +{ + return (writer)->ops->write_namespace(writer, env, prefix, namespace_uri); +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +axiom_xml_writer_write_default_namespace( + axiom_xml_writer_t * writer, + const axutil_env_t * env, + axis2_char_t * namespace_uri) +{ + return (writer)->ops->write_default_namespace(writer, env, namespace_uri); +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +axiom_xml_writer_write_comment( + axiom_xml_writer_t * writer, + const axutil_env_t * env, + axis2_char_t * value) +{ + return (writer)->ops->write_comment(writer, env, value); +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +axiom_xml_writer_write_processing_instruction( + axiom_xml_writer_t * writer, + const axutil_env_t * env, + axis2_char_t * target) +{ + return (writer)->ops->write_processing_instruction(writer, env, target); +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +axiom_xml_writer_write_processing_instruction_data( + axiom_xml_writer_t * writer, + const axutil_env_t * env, + axis2_char_t * target, + axis2_char_t * data) +{ + return (writer)->ops->write_processing_instruction_data(writer, env, target, data); +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +axiom_xml_writer_write_cdata( + axiom_xml_writer_t * writer, + const axutil_env_t * env, + axis2_char_t * data) +{ + return (writer)->ops->write_cdata(writer, env, data); +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +axiom_xml_writer_write_dtd( + axiom_xml_writer_t * writer, + const axutil_env_t * env, + axis2_char_t * dtd) +{ + return (writer)->ops->write_cdata(writer, env, dtd); +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +axiom_xml_writer_write_entity_ref( + axiom_xml_writer_t * writer, + const axutil_env_t * env, + axis2_char_t * name) +{ + return (writer)->ops->write_entity_ref(writer, env, name); +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +axiom_xml_writer_write_start_document( + axiom_xml_writer_t * writer, + const axutil_env_t * env) +{ + return (writer)->ops->write_start_document(writer, env); +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +axiom_xml_writer_write_start_document_with_version( + axiom_xml_writer_t * writer, + const axutil_env_t * env, + axis2_char_t * version) +{ + return (writer)->ops->write_start_document_with_version(writer, env, version); +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +axiom_xml_writer_write_start_document_with_version_encoding( + axiom_xml_writer_t * writer, + const axutil_env_t * env, + axis2_char_t * version, + axis2_char_t * encoding) +{ + return (writer)->ops->write_start_document_with_version_encoding(writer, env, encoding, version); +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +axiom_xml_writer_write_characters( + axiom_xml_writer_t * writer, + const axutil_env_t * env, + axis2_char_t * text) +{ + return (writer)->ops->write_characters(writer, env, text); +} + +AXIS2_EXTERN axis2_char_t *AXIS2_CALL +axiom_xml_writer_get_prefix( + axiom_xml_writer_t * writer, + const axutil_env_t * env, + axis2_char_t * uri) +{ + return (writer)->ops->get_prefix(writer, env, uri); +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +axiom_xml_writer_set_prefix( + axiom_xml_writer_t * writer, + const axutil_env_t * env, + axis2_char_t * prefix, + axis2_char_t * uri) +{ + return (writer)->ops->set_prefix(writer, env, prefix, uri); +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +axiom_xml_writer_set_default_prefix( + axiom_xml_writer_t * writer, + const axutil_env_t * env, + axis2_char_t * uri) +{ + return (writer)->ops->set_default_prefix(writer, env, uri); +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +axiom_xml_writer_write_encoded( + axiom_xml_writer_t * writer, + const axutil_env_t * env, + axis2_char_t * text, + int in_attr) +{ + return (writer)->ops->write_encoded(writer, env, text, in_attr); +} + +AXIS2_EXTERN void *AXIS2_CALL +axiom_xml_writer_get_xml( + axiom_xml_writer_t * writer, + const axutil_env_t * env) +{ + return (writer)->ops->get_xml(writer, env); +} + +AXIS2_EXTERN unsigned int AXIS2_CALL +axiom_xml_writer_get_xml_size( + axiom_xml_writer_t * writer, + const axutil_env_t * env) +{ + return (writer)->ops->get_xml_size(writer, env); +} + +AXIS2_EXTERN int AXIS2_CALL +axiom_xml_writer_get_type( + axiom_xml_writer_t * writer, + const axutil_env_t * env) +{ + return (writer)->ops->get_type(writer, env); +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +axiom_xml_writer_write_raw( + axiom_xml_writer_t * writer, + const axutil_env_t * env, + axis2_char_t * content) +{ + return (writer)->ops->write_raw(writer, env, content); +} + +AXIS2_EXTERN axis2_status_t AXIS2_CALL +axiom_xml_writer_flush( + axiom_xml_writer_t * writer, + const axutil_env_t * env) +{ + return (writer)->ops->flush(writer, env); +} |