summaryrefslogtreecommitdiffstats
path: root/guththila/include
diff options
context:
space:
mode:
Diffstat (limited to 'guththila/include')
-rw-r--r--guththila/include/guththila.h353
-rw-r--r--guththila/include/guththila_attribute.h127
-rw-r--r--guththila/include/guththila_buffer.h152
-rw-r--r--guththila/include/guththila_defines.h73
-rw-r--r--guththila/include/guththila_error.h96
-rw-r--r--guththila/include/guththila_namespace.h76
-rw-r--r--guththila/include/guththila_reader.h115
-rw-r--r--guththila/include/guththila_stack.h96
-rw-r--r--guththila/include/guththila_token.h174
-rw-r--r--guththila/include/guththila_xml_writer.h507
10 files changed, 1769 insertions, 0 deletions
diff --git a/guththila/include/guththila.h b/guththila/include/guththila.h
new file mode 100644
index 0000000..663883d
--- /dev/null
+++ b/guththila/include/guththila.h
@@ -0,0 +1,353 @@
+
+/*
+ * 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.
+ */
+#ifndef GUTHTHILA_H
+#define GUTHTHILA_H
+
+#include <guththila_defines.h>
+#include <guththila_token.h>
+#include <guththila_reader.h>
+#include <guththila_xml_writer.h>
+#include <guththila_attribute.h>
+#include <guththila_namespace.h>
+#include <guththila_buffer.h>
+#include <guththila_stack.h>
+#include <guththila_error.h>
+
+#include <axutil_utils.h>
+
+/*
+All the functions in this library does not check weather the given arguments are NULL.
+It is the responsblity of the user to check weather the arguments contain NULL values.
+*/
+EXTERN_C_START()
+
+enum guththila_status
+{
+ S_0 = 0,
+ S_1,
+ S_2,
+ S_3
+};
+
+enum guththila_UTF16_endianess
+{
+ None = 1,
+ LE,
+ BE
+};
+
+typedef enum guththila_type
+{
+ type_file_name = 0,
+ type_memory_buffer,
+ type_reader,
+ type_io
+} guththila_type_t;
+
+enum guththila_event_types
+{
+ GUTHTHILA_START_DOCUMENT =0,
+ GUTHTHILA_END_ELEMENT,
+ GUTHTHILA_CHARACTER,
+ GUTHTHILA_ENTITY_REFERANCE,
+ GUTHTHILA_COMMENT,
+ GUTHTHILA_SPACE,
+ GUTHTHILA_START_ELEMENT,
+ GUTHTHILA_EMPTY_ELEMENT
+};
+
+typedef struct guththila_s
+{
+ guththila_tok_list_t tokens; /* Token cache */
+
+ guththila_buffer_t buffer; /* Holding incoming xml string */
+
+ guththila_reader_t *reader; /* Reading the data */
+
+ guththila_token_t *prefix; /* Prefix of the xml element */
+
+ guththila_token_t *name; /* xml element local name */
+
+ guththila_token_t *value; /* text of a xml element */
+
+ guththila_stack_t elem; /* elements are put in a stack */
+
+ guththila_stack_t attrib; /* Attributes are put in a stack */
+
+ guththila_stack_t namesp; /* namespaces are put in a stack */
+
+ int status;
+
+ int guththila_event; /* Current event */
+
+ size_t next; /* Keep track of the position in the xml string */
+
+ int last_start; /* Keep track of the starting position of the last token */
+
+ guththila_token_t *temp_prefix; /* Temporery location for prefixes */
+
+ guththila_token_t *temp_name; /* Temporery location for names */
+
+ guththila_token_t *temp_tok; /* We don't know this until we close it */
+} guththila_t;
+
+/*
+ * An element will contain one of these things if it has namespaces
+ * */
+typedef struct guththila_elem_namesp_s
+{
+ guththila_namespace_t *namesp; /* Array of namespaces */
+ int no; /*Number of namespace in the element */
+ int size; /* Allocated size */
+} guththila_elem_namesp_t;
+
+/*
+ * Element.
+ */
+typedef struct guththila_element_s
+{
+ guththila_token_t *name; /* local name */
+
+ guththila_token_t *prefix; /* prefix */
+
+ int is_namesp; /* Positive if a namespace is present */
+} guththila_element_t;
+
+/* Initialize the parser */
+GUTHTHILA_EXPORT int GUTHTHILA_CALL
+guththila_init(guththila_t * m, void *reader,
+ const axutil_env_t * env);
+
+/* Uninitialize the parser */
+GUTHTHILA_EXPORT int GUTHTHILA_CALL
+guththila_un_init(guththila_t * m, const axutil_env_t * env);
+
+/* Still not used */
+typedef void(GUTHTHILA_CALL * guththila_error_func)(void *arg,
+ const guththila_char_t *msg,
+ guththila_error_level level,
+ void *locator);
+
+/*
+ * Parse the xml and return an event. If something went wrong it will return -1.
+ * The events are of the type guththila_event_types. According to the event
+ * user can get the required information using the appriate functions.
+ * @param g pointer to a guththila_t structure
+ * @param env the environment
+ */
+GUTHTHILA_EXPORT int GUTHTHILA_CALL
+guththila_next(guththila_t * g, const axutil_env_t * env);
+
+/*
+ * Return the number of attributes in the current element.
+ * @param g pointer to a guththila_t structure
+ * @param env the environment
+ */
+GUTHTHILA_EXPORT int GUTHTHILA_CALL
+guththila_get_attribute_count(guththila_t * g, const axutil_env_t * env);
+
+/*
+ * Return the attribute name.
+ * @param g pointer to a guththila_t structure
+ * @param att pointer to a attribute
+ * @param env the environment
+ */
+GUTHTHILA_EXPORT guththila_char_t * GUTHTHILA_CALL
+guththila_get_attribute_name(guththila_t * g, guththila_attr_t * att,
+ const axutil_env_t * env);
+
+/*
+ * Return the attribute value.
+ * @param g pointer to a guththila_t structure
+ * @param att pointer to a attribute
+ * @param env the environment
+ */
+GUTHTHILA_EXPORT guththila_char_t * GUTHTHILA_CALL
+guththila_get_attribute_value(guththila_t * g,
+ guththila_attr_t * att,
+ const axutil_env_t * env);
+
+/*
+ * Return the attribute prefix.
+ * @param g pointer to a guththila_t structure
+ * @param att pointer to a attribute
+ * @param env the environment
+ */
+GUTHTHILA_EXPORT guththila_char_t *GUTHTHILA_CALL
+guththila_get_attribute_prefix(guththila_t * g,
+ guththila_attr_t * att,
+ const axutil_env_t * env);
+
+/*
+ * Return the attribute
+ * @param g pointer to a guththila_t structure
+ * @param env the environment
+ */
+GUTHTHILA_EXPORT guththila_attr_t *GUTHTHILA_CALL
+guththila_get_attribute(guththila_t * g, const axutil_env_t * env);
+
+/*
+ * Return the name of the attribute by the attribute bumber.
+ * First attribute will be 1.
+ * @param g pointer to a guththila_t structure
+ * @param index position of the attribute
+ * @param env the environment
+ */
+GUTHTHILA_EXPORT guththila_char_t *GUTHTHILA_CALL
+guththila_get_attribute_name_by_number(guththila_t * g, int index,
+ const axutil_env_t *env);
+
+/*
+ * Return the attribute value by number.
+ * First attribute will be 1.
+ * @param g pointer to a guththila_t structure
+ * @param index position of the attribute
+ * @param env the environment
+ */
+GUTHTHILA_EXPORT guththila_char_t *GUTHTHILA_CALL
+guththila_get_attribute_value_by_number(guththila_t * g, int index,
+ const axutil_env_t *env);
+
+/*
+ * Return the prefix of the attribute.
+ * First attribute will be 1.
+ * @param g pointer to a guththila_t structure
+ * @param index position of the attribute
+ * @param env the environment
+ */
+GUTHTHILA_EXPORT guththila_char_t *GUTHTHILA_CALL
+guththila_get_attribute_prefix_by_number(guththila_t * g, int index,
+ const axutil_env_t *env);
+
+/*
+ * Return the name of the element.
+ * @param g pointer to a guththila_t structure
+ * @param env the environment
+ */
+GUTHTHILA_EXPORT guththila_char_t *GUTHTHILA_CALL
+guththila_get_name(guththila_t * g, const axutil_env_t * env);
+
+/*
+ * Return the prefix of the element.
+ * @param g pointer to a guththila_t structure
+ * @param env the environment
+ */
+GUTHTHILA_EXPORT guththila_char_t *GUTHTHILA_CALL
+guththila_get_prefix(guththila_t * g, const axutil_env_t * env);
+
+/*
+ * Return the text of the element.
+ * @param g pointer to a guththila_t structure
+ * @param env the environment
+ */
+GUTHTHILA_EXPORT guththila_char_t *GUTHTHILA_CALL
+guththila_get_value(guththila_t * g, const axutil_env_t * env);
+
+/*
+ * Return the namespace of the element.
+ * @param g pointer to a guththila_t structure
+ * @param env the environment
+ */
+GUTHTHILA_EXPORT guththila_namespace_t *GUTHTHILA_CALL
+guththila_get_namespace(guththila_t * g, const axutil_env_t * env);
+
+/*
+ * Return the number of namespaces in the element.
+ * @param g pointer to a guththila_t structure
+ * @param env the environment
+ */
+GUTHTHILA_EXPORT int GUTHTHILA_CALL
+guththila_get_namespace_count(guththila_t * g, const axutil_env_t * env);
+
+/*
+ * Return the namespace uri of the given namespace.
+ * @param g pointer to a guththila_t structure
+ * @param ns pointer to a namespace
+ * @param env the environment
+ */
+GUTHTHILA_EXPORT guththila_char_t * GUTHTHILA_CALL
+guththila_get_namespace_uri(guththila_t * g, guththila_namespace_t * ns,
+ const axutil_env_t * env);
+
+/*
+ * Return the prefix of the namespace.
+ * @param g pointer to a guththila_t structure
+ * @param ns pointer to a namespace
+ * @param env the environment
+ */
+GUTHTHILA_EXPORT guththila_char_t *GUTHTHILA_CALL
+guththila_get_namespace_prefix(guththila_t * p, guththila_namespace_t * ns,
+ const axutil_env_t * env);
+
+/*
+ * Return the prefix of the namespace at the given position.
+ * First namespace will have the value 1.
+ * @param g pointer to a guththila_t structure
+ * @param index position of the namespace
+ * @param env the environment
+ */
+GUTHTHILA_EXPORT guththila_char_t *GUTHTHILA_CALL
+guththila_get_namespace_prefix_by_number(guththila_t * g, int index,
+ const axutil_env_t *env);
+
+/*
+ * Get the uri of the namespace at the given position.
+ * First namespace will have the value 1.
+ * @param g pointer to a guththila_t structure
+ * @param index position of the namespace
+ * @param env the environment
+ */
+GUTHTHILA_EXPORT guththila_char_t *GUTHTHILA_CALL
+guththila_get_namespace_uri_by_number(guththila_t * g, int index,
+ const axutil_env_t *env);
+
+/*
+ * Get the attribute namespace of the attribute at the given position.
+ * @param g pointer to a guththila_t structure
+ * @param index position of the namespace
+ * @param env the environment
+ */
+GUTHTHILA_EXPORT guththila_char_t *GUTHTHILA_CALL
+guththila_get_attribute_namespace_by_number(guththila_t *g, int index,
+ const axutil_env_t *env);
+
+/*
+ * Get the encoding. at the moment we don't support UNICODE
+ * @param g pointer to a guththila_t structure
+ * @param env the environment
+ */
+GUTHTHILA_EXPORT guththila_char_t *GUTHTHILA_CALL
+guththila_get_encoding(guththila_t * p, const axutil_env_t * env);
+
+/*
+ * To do. Implement a proper error handling mechanism.
+ * @param g pointer to a guththila_t structure
+ * @param env the environment
+ */
+GUTHTHILA_EXPORT void GUTHTHILA_CALL
+guththila_set_error_handler(guththila_t * m, guththila_error_func,
+ const axutil_env_t * env);
+
+GUTHTHILA_EXPORT guththila_char_t *GUTHTHILA_CALL
+guththila_get_current_buffer(
+ guththila_t * m,
+ const axutil_env_t * env);
+
+EXTERN_C_END()
+#endif
+
diff --git a/guththila/include/guththila_attribute.h b/guththila/include/guththila_attribute.h
new file mode 100644
index 0000000..8752283
--- /dev/null
+++ b/guththila/include/guththila_attribute.h
@@ -0,0 +1,127 @@
+
+/*
+ * 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.
+ */
+#ifndef GUTHTHILA_ATTRIBUTE_H
+#define GUTHTHILA_ATTRIBUTE_H
+
+#include <guththila_defines.h>
+#include <guththila_token.h>
+#include <axutil_utils.h>
+
+EXTERN_C_START()
+
+#ifndef GUTHTHILA_ATTR_DEF_SIZE
+#define GUTHTHILA_ATTR_DEF_SIZE 16
+#endif
+
+/* Representation of an attribute */
+typedef struct guththila_attr_s
+{
+ guththila_token_t *pref; /* Prefix */
+ guththila_token_t *name; /* Name */
+ guththila_token_t *val; /* Value */
+} guththila_attr_t;
+
+typedef struct guththila_attr_list_s
+{
+ guththila_attr_t *list;
+ guththila_stack_t fr_stack;
+ int size;
+ int capacity;
+} guththila_attr_list_t;
+
+/**
+* Create function of guththila_attr_list_t type structure
+* @param env environment, MUST NOT be NULL.
+* return new pointer to structure guththila_attr_list_s with initializing stack
+* fr_stack
+*/
+guththila_attr_list_t *
+GUTHTHILA_CALL guththila_attr_list_create(const axutil_env_t * env);
+
+/**
+ * Initializing function of guththila_attr_list_t type structure,same
+ * thing done by the create method
+ * @param at_list keeps the list of attributes in this structure using
+ * a guththila_stack_t variable
+ * @param env environment, MUST NOT be NULL.
+ * return status of op AXIS2_SUCCESS on success,
+ * AXIS2_FAILURE on error
+ */
+int GUTHTHILA_CALL
+guththila_attr_list_init(
+ guththila_attr_list_t * at_list,
+ const axutil_env_t * env);
+
+/**
+ * @param at_list keeps the list of attributes in this structure using
+ * a guththila_stack_t variable
+ * @param env environment, MUST NOT be NULL.
+ * return the top value of the stack which is inside guththila_attr_list_t
+ */
+guththila_attr_t *
+GUTHTHILA_CALL guththila_attr_list_get(guththila_attr_list_t * at_list,
+ const axutil_env_t * env);
+
+
+/**
+ * This method push the given attribute in to the stack which is a
+ * member of guththila_attr_list_t
+ * @param at_list keeps the list of attributes in this structure using
+ * a guththila_stack_t variable
+ * @param attr contains attribute with attribute name,value,and prefix
+ * @param env environment, MUST NOT be NULL.
+ * return status of op AXIS2_SUCCESS on success,
+ * AXIS2_FAILURE on error
+ */
+int GUTHTHILA_CALL
+guththila_attr_list_release(
+ guththila_attr_list_t * at_list,
+ guththila_attr_t * attr,
+ const axutil_env_t * env);
+
+/**
+ * Free method for the stack which is inside guththila_attr_list_s
+ * structure, free the stack and other members
+ * @param at_list keeps the list of attributes in this structure using
+ * a guththila_stack_t variable
+ * @param env environment, MUST NOT be NULL.
+ * return status of op AXIS2_SUCCESS on success,
+ * AXIS2_FAILURE on error
+ */
+void GUTHTHILA_CALL
+msuila_attr_list_free_data(
+ guththila_attr_list_t * at_list,
+ const axutil_env_t * env);
+
+/**
+ * Free method for guththila_attr_list_s structure,this free at_list too.
+ * @param at_list keeps the list of attributes in this structure using
+ * a guththila_stack_t variable
+ * @param attr contains attribute with attribute name,value,and prefix
+ * @param env environment, MUST NOT be NULL.
+ * return status of op AXIS2_SUCCESS on success,
+ * AXIS2_FAILURE on error
+ */
+void GUTHTHILA_CALL
+guththila_attr_list_free(
+ guththila_attr_list_t * at_list,
+ const axutil_env_t * env);
+
+EXTERN_C_END()
+#endif /* */
+
diff --git a/guththila/include/guththila_buffer.h b/guththila/include/guththila_buffer.h
new file mode 100644
index 0000000..8f94fde
--- /dev/null
+++ b/guththila/include/guththila_buffer.h
@@ -0,0 +1,152 @@
+
+/*
+ * 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.
+ */
+#ifndef GUTHTHILA_BUFFER_H
+#define GUTHTHILA_BUFFER_H
+
+#include <guththila_defines.h>
+#include <axutil_utils.h>
+
+EXTERN_C_START()
+
+typedef enum guththila_buffer_type
+{
+ GUTHTHILA_SINGLE_BUFFER = 0, /* One buffer */
+ GUTHTHILA_MULTIPLE_BUFFER /* Mulitple buffers in a buff array */
+} guththila_buffer_type_t;
+
+typedef struct guththila_buffer_s
+{
+ /* Required to manupulate multiple buffers */
+ size_t *data_size; /* Array containing filled sizes of buffers */
+ size_t *buffs_size; /* Array containing actual sizes of buffers */
+ guththila_char_t **buff; /* Array of buffers */
+ int cur_buff; /* Current buffer */
+ int cur_buff_pos; /* Position of the current buffer */
+ size_t pre_tot_data; /* All the data in the previous buffers. Not include cur */
+ unsigned int no_buffers; /* No of buffers */
+ short type; /* Buffer type */
+ guththila_char_t *xml; /* All the buffers serialized together */
+} guththila_buffer_t;
+
+#define GUTHTHILA_BUFFER_DEF_SIZE 16384
+#define GUTHTHILA_BUFFER_DEF_MIN_SIZE 512
+#define GUTHTHILA_BUFFER_NUMBER_OF_BUFFERS 16
+
+#ifndef GUTHTHILA_BUFFER_SIZE
+#define GUTHTHILA_BUFFER_SIZE(_buffer) (_buffer.size)
+#endif
+
+#ifndef GUTHTHILA_BUFFER_CURRENT_BUFF
+#define GUTHTHILA_BUFFER_CURRENT_BUFF(_buffer) ((_buffer).buff[(_buffer).cur_buff] + (_buffer).data_size[(_buffer).cur_buff])
+#endif
+
+#ifndef GUTHTHILA_BUFFER_CURRENT_BUFF_SIZE
+#define GUTHTHILA_BUFFER_CURRENT_BUFF_SIZE(_buffer) ((_buffer).buffs_size[(_buffer).cur_buff] - (_buffer).data_size[(_buffer).cur_buff])
+#endif
+
+#ifndef GUTHTHILA_BUFFER_CURRENT_DATA_SIZE
+#define GUTHTHILA_BUFFER_CURRENT_DATA_SIZE(_buffer) ((_buffer).data_size[(_buffer).cur_buff])
+#endif
+
+#ifndef GUTHTHILA_BUFFER_PRE_DATA_SIZE
+#define GUTHTHILA_BUFFER_PRE_DATA_SIZE(_buffer) ((_buffer).pre_tot_data)
+#endif
+
+/*We never consider tokens not in the current buffer*/
+#ifndef GUTHTHILA_BUF_POS
+#define GUTHTHILA_BUF_POS(_buffer, _pos) ((_buffer).buff[(_buffer).cur_buff] + _pos - (_buffer).pre_tot_data)
+#endif
+
+/**
+ * This method is the create method of guththila_buffer_s structure
+ * @param buffer structure which is going to create
+ * @param size size of the buffer which is going to create
+ * @param env environment, MUST NOT be NULL.
+ * return status of op AXIS2_SUCCESS on success,
+ * AXIS2_FAILURE on error
+ */
+int GUTHTHILA_CALL
+guththila_buffer_init(guththila_buffer_t * buffer,
+ int size,
+ const axutil_env_t * env);
+
+/**
+ * This is the free method of guththila_buffer_s structure
+ * @param buffer structure which is going to create
+ * @param env environment, MUST NOT be NULL.
+ * return status of op AXIS2_SUCCESS on success,
+ * AXIS2_FAILURE on error
+ */
+int GUTHTHILA_CALL
+guththila_buffer_un_init(guththila_buffer_t * buffer,
+ const axutil_env_t * env);
+
+/**
+ * This method creates a new buffer and copy the content of given
+ * data by buffer variable
+ * @param mu_buff structure which is going to create
+ * @param buffer data to copy in to new buffer
+ * @param size size of the buffer to create
+ * @param env environment, MUST NOT be NULL.
+ * return status of op AXIS2_SUCCESS on success,
+ * AXIS2_FAILURE on error
+ */
+int GUTHTHILA_CALL
+guththila_buffer_init_for_buffer(guththila_buffer_t * mu_buff,
+ guththila_char_t *buffer,
+ int size,
+ const axutil_env_t * env);
+
+void *GUTHTHILA_CALL
+guththila_get_position(guththila_buffer_t * buffer,
+ int pos,
+ const axutil_env_t * env);
+
+int GUTHTHILA_CALL
+guththila_buffer_next(guththila_buffer_t * buffer,
+ const axutil_env_t * env);
+
+
+/**
+ * This method create new xml element which is having the
+ * size of cur_buff
+ * data by buffer variable
+ * @param buffer
+ * @param env environment, MUST NOT be NULL.
+ * return xml element of guththila_buffer_s structure
+ */
+void *GUTHTHILA_CALL
+guththila_buffer_get(guththila_buffer_t * buffer,
+ const axutil_env_t * env);
+
+
+int GUTHTHILA_CALL
+guththila_buffer_shift(guththila_buffer_t * buffer,
+ int no, const axutil_env_t * env);
+
+int GUTHTHILA_CALL
+guththila_buffer_insert_data(guththila_buffer_t * buffer,
+ void *buff, size_t buff_len,
+ const axutil_env_t * env);
+
+EXTERN_C_END()
+#endif
+
+
+
+
diff --git a/guththila/include/guththila_defines.h b/guththila/include/guththila_defines.h
new file mode 100644
index 0000000..d297f55
--- /dev/null
+++ b/guththila/include/guththila_defines.h
@@ -0,0 +1,73 @@
+
+/*
+ * 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.
+ */
+#ifndef GUTHTHILA_DEFINES_H
+#define GUTHTHILA_DEFINES_H
+
+#if defined(_WIN32)
+#define GUTHTHILA_EXPORT __declspec(dllexport)
+#else
+#define GUTHTHILA_EXPORT
+#endif
+
+#if defined(__GNUC__)
+#if defined(__i386)
+#define GUTHTHILA_CALL __attribute__((cdecl))
+#else
+#define GUTHTHILA_CALL
+#endif
+#else
+#if defined(__unix)
+#define GUTHTHILA_CALL
+#else
+#define GUTHTHILA_CALL __stdcall
+#endif
+#endif
+
+#ifndef guththila_char_t
+#define guththila_char_t char
+#endif
+
+#ifndef GUTHTHILA_SUCCESS
+#define GUTHTHILA_SUCCESS 1
+#endif
+
+#ifndef GUTHTHILA_FAILURE
+#define GUTHTHILA_FAILURE 0
+#endif
+
+#ifdef __cplusplus
+#define EXTERN_C_START() extern "C" {
+#define EXTERN_C_END() }
+#else
+#define EXTERN_C_START()
+#define EXTERN_C_END()
+#endif
+
+#ifndef GUTHTHILA_EOF
+#define GUTHTHILA_EOF (-1)
+#endif
+
+#ifndef GUTHTHILA_FALSE
+#define GUTHTHILA_FALSE 0
+#endif
+
+#ifndef GUTHTHILA_TRUE
+#define GUTHTHILA_TRUE 1
+#endif
+
+#endif
diff --git a/guththila/include/guththila_error.h b/guththila/include/guththila_error.h
new file mode 100644
index 0000000..834e954
--- /dev/null
+++ b/guththila/include/guththila_error.h
@@ -0,0 +1,96 @@
+
+/*
+ * 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_defines.h>
+
+#ifndef GUTHTHILA_ERROR_H
+#define GUTHTHILA_ERROR_H
+EXTERN_C_START() typedef enum guththila_error_l
+{
+ GUTHTHILA_VALIDITY_ERROR,
+ GUTHTHILA_VALIDITY_WARNING,
+ GUTHTHILA_PARSER_ERROR,
+ GUTHTHILA_PARSER_WARNING
+} guththila_error_level;
+enum guththila_error_codes
+{
+ GUTHTHILA_ERROR_NONE =
+ 0, GUTHTHILA_ERROR_NO_MEMORY,
+ GUTHTHILA_ERROR_INVALID_NULL_PARAMETER,
+ GUTHTHILA_ERROR_INVALID_ITERATOR_STATE,
+ GUTHTHILA_ERROR_INVALID_NODE_TYPE,
+ GUTHTHILA_STREAM_WRITER_ERROR_NOT_IN_GUTHTHILA_START_ELEMENT,
+ GUTHTHILA_STREAM_WRITER_ERROR_WRITING_TO_STREAM,
+ GUTHTHILA_STREAM_WRITER_ERROR_STREAM_STRUCT_NULL,
+ GUTHTHILA_STREAM_WRITER_ERROR_LOCAL_NAME_NULL,
+ GUTHTHILA_STREAM_WRITER_ERROR_GUTHTHILA_namespace_t_NULL,
+ GUTHTHILA_STREAM_WRITER_ERROR_PREFIX_NULL,
+ GUTHTHILA_STREAM_WRITER_ERROR_GUTHTHILA_namespace_t_NOT_DECLARED,
+ GUTHTHILA_STREAM_WRITER_ERROR_GUTHTHILA_element_t_GUTHTHILA_stack_t_EMPTY,
+ GUTHTHILA_STREAM_WRITER_ERROR_ILLEGAL_STATE,
+ GUTHTHILA_STREAM_WRITER_ERROR_GUTHTHILA_COMMENT_NULL,
+ GUTHTHILA_STREAM_WRITER_ERROR_ILLEGAL_GUTHTHILA_COMMENT,
+ GUTHTHILA_STREAM_WRITER_ERROR_PROCESSING_INSTRUCTION_TARGET_NULL,
+ GUTHTHILA_STREAM_WRITER_ERROR_CDATA_NULL,
+ GUTHTHILA_STREAM_WRITER_ERROR_ILLEGAL_CDATA,
+ GUTHTHILA_STREAM_WRITER_ERROR_DTD_NULL,
+ GUTHTHILA_STREAM_WRITER_ERROR_ENTITY_REF_NULL,
+ GUTHTHILA_STREAM_WRITER_ERROR_ILLEGAL_XML_VERSION,
+ GUTHTHILA_STREAM_WRITER_ERROR_TEXT_NULL,
+ GUTHTHILA_STREAM_WRITER_ERROR_ILLEGAL_PREFIX,
+ GUTHTHILA_STREAM_WRITER_ERROR_OUT_OF_MEMORY,
+ GUTHTHILA_STREAM_WRITER_ERROR_FILE_NOT_FOUND,
+ GUTHTHILA_STREAM_READER_ERROR_OUT_OF_MEMORY,
+ GUTHTHILA_ERROR_INVALID_ENCODING_DECLARATION,
+ GUTHTHILA_ERROR_UNEXPECTED_UTF16_EOF,
+ GUTHTHILA_ERROR_UNEXPECTED_EOF,
+ GUTHTHILA_ERROR_PROCESS_EQUAL,
+ GUTHTHILA_ERROR_INCORRECT_VERSION_INFO,
+ GUTHTHILA_ERROR_INCORRECT_XML_DECLARATION,
+ GUTHTHILA_ERROR_VERSION_INFO_NOT_FOUND,
+ GUTHTHILA_ERROR_ENCODING_DECLARATION_ERROR,
+ GUTHTHILA_ERROR_STANDALONE_ERROR_IN_YES,
+ GUTHTHILA_ERROR_STANDALONE_ERROR_IN_NO,
+ GUTHTHILA_ERROR_STANDALONE_ERROR_YES_OR_NO_NOT_AVAILABLE,
+ GUTHTHILA_ERROR_MISSING_GREATER_SIGN_IN_XML_DECLARATION,
+ GUTHTHILA_ERROR_INVALID_NAME_STARTING_CHARACTER,
+ GUTHTHILA_ERROR_QUOTES_NOT_FOUND_BEFORE_ATTRIBUTE_VALUE,
+ GUTHTHILA_ERROR_EMPTY_ELEMENT_NOT_CLOSED,
+ GUTHTHILA_ERROR_END_TAG_NOT_CLOSED,
+ GUTHTHILA_ERROR_MORE_HYPENS_OCCURED_IN_COMMENT,
+ GUTHTHILA_ERROR_TOKENIZE_ERROR,
+ GUTHTHILA_ERROR_INVALID_TOKEN_TYPE,
+ GUTHTHILA_ERROR_NULL_ATTRIBUTE_NAME,
+ GUTHTHILA_ERROR_NULL_ATTRIBUTE_VALUE,
+ GUTHTHILA_ERROR_NULL_ATTRIBUTE_PREFIX,
+ GUTHTHILA_ERROR_REQUESTED_NUMBER_GREATER_THAN_STACK_SIZE,
+ GUTHTHILA_WRITER_ERROR_EMPTY_ARGUMENTS,
+ GUTHTHILA_WRITER_ERROR_NON_EXSISTING_PREFIX,
+ GUTHTHILA_WRITER_ERROR_EMPTY_WRITER,
+ GUTHTHILA_WRITER_ERROR_NON_MATCHING_ELEMENTS,
+ GUTHTHILA_WRITER_ERROR_INVALID_BUFFER,
+ GUTHTHILA_WRITER_ERROR_INVALID_CHAR_IN_NAME,
+ GUTHTHILA_WRITER_ERROR_XML_STRING_IN_NAME,
+ GUTHTHILA_WRITER_ERROR_EXCESS_HYPENS_IN_COMMENT,
+ GUTHTHILA_WRITER_ERROR_INVALID_CHAR_IN_ATTRIBUTE,
+ GUTHTHILA_WRITER_ERROR_NON_EXSISTING_URI,
+ GUTHTHILA_WRITER_ERROR_SAME_ATTRIBUTE_REPEAT,
+ GUTHTHILA_ERROR_ATTRIBUTE_FREE
+};
+EXTERN_C_END()
+#endif /* */
+
diff --git a/guththila/include/guththila_namespace.h b/guththila/include/guththila_namespace.h
new file mode 100644
index 0000000..a845665
--- /dev/null
+++ b/guththila/include/guththila_namespace.h
@@ -0,0 +1,76 @@
+
+/*
+ * 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.
+ */
+#ifndef GUTHTHILA_NAMESPACE_H
+#define GUTHTHILA_NAMESPACE_H
+
+#include <guththila_defines.h>
+#include <guththila_token.h>
+#include <axutil_utils.h>
+EXTERN_C_START()
+
+#ifndef GUTHTHILA_NAMESPACE_DEF_SIZE
+#define GUTHTHILA_NAMESPACE_DEF_SIZE 4
+#endif
+
+typedef struct guththila_namespace_s
+{
+ guththila_token_t *name; /* Name */
+ guththila_token_t *uri; /* URI */
+} guththila_namespace_t;
+
+typedef struct guththila_namespace_list_s
+{
+ guththila_namespace_t *list;
+ guththila_stack_t fr_stack;
+ int size;
+ int capacity;
+} guththila_namespace_list_t;
+
+guththila_namespace_list_t *GUTHTHILA_CALL
+guththila_namespace_list_create(
+ const axutil_env_t * env);
+
+int GUTHTHILA_CALL
+guththila_namespace_list_init(
+ guththila_namespace_list_t * at_list,
+ const axutil_env_t * env);
+
+guththila_namespace_t * GUTHTHILA_CALL
+guththila_namespace_list_get(
+ guththila_namespace_list_t *at_list,
+ const axutil_env_t * env);
+
+int GUTHTHILA_CALL
+guththila_namespace_list_release(
+ guththila_namespace_list_t * at_list,
+ guththila_namespace_t * namesp,
+ const axutil_env_t * env);
+
+void GUTHTHILA_CALL
+msuila_namespace_list_free_data(
+ guththila_namespace_list_t * at_list,
+ const axutil_env_t * env);
+
+void GUTHTHILA_CALL
+guththila_namespace_list_free(
+ guththila_namespace_list_t * at_list,
+ const axutil_env_t * env);
+
+EXTERN_C_END()
+#endif
+
diff --git a/guththila/include/guththila_reader.h b/guththila/include/guththila_reader.h
new file mode 100644
index 0000000..cad53a1
--- /dev/null
+++ b/guththila/include/guththila_reader.h
@@ -0,0 +1,115 @@
+
+/*
+ * 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.
+ */
+#ifndef GUTHTHILA_READER_H
+#define GUTHTHILA_READER_H
+
+#include <stdio.h>
+#include <guththila_defines.h>
+#include <axutil_utils.h>
+
+EXTERN_C_START()
+
+typedef int(GUTHTHILA_CALL * GUTHTHILA_READ_INPUT_CALLBACK)(
+ guththila_char_t *buffer,
+ int size,
+ void *ctx);
+
+enum guththila_reader_type
+{
+ GUTHTHILA_FILE_READER = 1,
+ GUTHTHILA_IO_READER,
+ GUTHTHILA_MEMORY_READER
+};
+
+typedef struct guththila_reader_s
+{
+ int type; /* Type of reader */
+ FILE *fp; /* File pointer */
+ guththila_char_t *buff; /* Buffer */
+ int buff_size; /* Buff size */
+ GUTHTHILA_READ_INPUT_CALLBACK input_read_callback; /* Call back */
+ void *context; /* Context */
+} guththila_reader_t;
+
+#ifndef GUTHTHILA_READER_SET_LAST_START
+#define GUTHTHILA_READER_SET_LAST_START(_reader, _start) ((_reader)->start = _start)
+#endif
+
+#ifndef GUTHTHILA_READER_STEP_BACK
+#define GUTHTHILA_READER_STEP_BACK(_reader) ((_reader->next--))
+#endif
+
+/*
+ * Reading a file.
+ * @param filename name of the file
+ * @param env environment
+ */
+GUTHTHILA_EXPORT guththila_reader_t * GUTHTHILA_CALL
+guththila_reader_create_for_file(guththila_char_t *filename,
+ const axutil_env_t * env);
+
+/*
+ * Reading from a call back function.
+ * @param input_read_callback function pointer to read data
+ * @param ctx context
+ * @param env environment
+ */
+GUTHTHILA_EXPORT guththila_reader_t * GUTHTHILA_CALL
+guththila_reader_create_for_io(GUTHTHILA_READ_INPUT_CALLBACK
+ input_read_callback, void *ctx,
+ const axutil_env_t * env);
+
+/*
+ * Reading from memory buffer.
+ * @param buffer buffer
+ * @param size size of the buffer
+ * @param env environment
+ */
+GUTHTHILA_EXPORT guththila_reader_t * GUTHTHILA_CALL
+guththila_reader_create_for_memory(void *buffer,
+ int size,
+ const axutil_env_t * env);
+
+/*
+ * Read the specified number of character to the given buffer.
+ * @param r reader
+ * @param buffer buffer to place the read data
+ * @param offset position to place the data on the given buffer
+ * @param length number of bytes to read
+ * @param env environment
+ * @return number of bytes put in to the buffer. -1 if end of the read.
+ */
+GUTHTHILA_EXPORT int GUTHTHILA_CALL guththila_reader_read(
+ guththila_reader_t * r,
+ guththila_char_t * buffer,
+ int offset,
+ int length,
+ const axutil_env_t * env);
+
+/*
+ * Free the reader.
+ * @param r reader
+ * @param env environment
+ */
+GUTHTHILA_EXPORT void GUTHTHILA_CALL guththila_reader_free(
+ guththila_reader_t * r,
+ const axutil_env_t * env);
+
+EXTERN_C_END()
+#endif /* */
+
diff --git a/guththila/include/guththila_stack.h b/guththila/include/guththila_stack.h
new file mode 100644
index 0000000..3520d73
--- /dev/null
+++ b/guththila/include/guththila_stack.h
@@ -0,0 +1,96 @@
+
+/*
+ * 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.
+ */
+#ifndef GUTHTHILA_STACK_H
+#define GUTHTHILA_STACK_H
+
+#include <stdio.h>
+#include <stdlib.h>
+
+#include <guththila_defines.h>
+#include <axutil_utils.h>
+#define GUTHTHILA_STACK_DEFAULT 16
+
+EXTERN_C_START()
+
+typedef struct guththila_stack_s
+{
+ /* Number of Items in the stack */
+ int top;
+ /* Max number of Items that can be hold in data */
+ int max;
+ void ** data;
+} guththila_stack_t;
+
+#ifndef GUTHTHILA_STACK_SIZE
+#define GUTHTHILA_STACK_SIZE(_stack) ((_stack).top)
+#endif
+
+#ifndef GUTHTHILA_STACK_TOP_INDEX
+#define GUTHTHILA_STACK_TOP_INDEX(_stack) (((_stack).top - 1))
+#endif
+
+int GUTHTHILA_CALL
+guththila_stack_init(
+ guththila_stack_t * stack,
+ const axutil_env_t * env);
+
+void GUTHTHILA_CALL
+guththila_stack_free(
+ guththila_stack_t * stack,
+ const axutil_env_t * env);
+
+void GUTHTHILA_CALL
+guththila_stack_un_init(
+ guththila_stack_t * stack,
+ const axutil_env_t * env);
+
+void * GUTHTHILA_CALL
+guththila_stack_pop(
+ guththila_stack_t * stack,
+ const axutil_env_t * env);
+
+int GUTHTHILA_CALL
+guththila_stack_push(
+ guththila_stack_t * stack,
+ void *data,
+ const axutil_env_t * env);
+
+void * GUTHTHILA_CALL
+guththila_stack_peek(
+ guththila_stack_t * stack,
+ const axutil_env_t * env);
+
+void * GUTHTHILA_CALL
+guththila_stack_get_by_index(
+ guththila_stack_t * stack,
+ int index,
+ const axutil_env_t * env);
+
+int GUTHTHILA_CALL
+guththila_stack_del_top(
+ guththila_stack_t * stack,
+ const axutil_env_t * env);
+
+int GUTHTHILA_CALL
+guththila_stack_is_empty(
+ guththila_stack_t * stack,
+ const axutil_env_t * env);
+
+EXTERN_C_END()
+#endif
+
diff --git a/guththila/include/guththila_token.h b/guththila/include/guththila_token.h
new file mode 100644
index 0000000..ae8719c
--- /dev/null
+++ b/guththila/include/guththila_token.h
@@ -0,0 +1,174 @@
+
+/*
+ * 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.
+ */
+#ifndef GUTHTHILA_TOKEN_H
+#define GUTHTHILA_TOKEN_H
+
+#include <guththila_defines.h>
+#include <guththila_stack.h>
+
+EXTERN_C_START()
+
+typedef struct guththila_token_s
+{
+ short type;
+ guththila_char_t *start;
+ int _start;
+ size_t size;
+ int last;
+ int ref;
+} guththila_token_t;
+
+enum guththila_token_type
+{
+ _Unknown = 1,
+ _name,
+ _attribute_name,
+ _attribute_value,
+ _prefix,
+ _char_data,
+ _text_data
+};
+
+typedef struct guththila_tok_list_s
+{
+ guththila_stack_t fr_stack;
+ guththila_token_t **list;
+ int no_list;
+ int cur_list;
+ int *capacity;
+} guththila_tok_list_t;
+
+#ifndef GUTHTHILA_TOK_DEF_SIZE
+#define GUTHTHILA_TOK_DEF_SIZE 16
+#endif
+
+#ifndef GUTHTHILA_TOK_DEF_LIST_SIZE
+#define GUTHTHILA_TOK_DEF_LIST_SIZE 16
+#endif
+
+#ifndef GUTHTHILA_TOKEN_LEN
+#define GUTHTHILA_TOKEN_LEN(tok) (tok->size)
+#endif
+
+#ifndef GUTHTHILA_TOKEN_TO_STRING
+#define GUTHTHILA_TOKEN_TO_STRING(tok, string, _env) \
+ { \
+ string = (guththila_char_t *) AXIS2_MALLOC(_env->allocator, (GUTHTHILA_TOKEN_LEN(tok) + 1) * sizeof(guththila_char_t)); \
+ memcpy(string, (tok)->start, GUTHTHILA_TOKEN_LEN(tok)); \
+ string[GUTHTHILA_TOKEN_LEN(tok)] = 0; \
+ }
+#endif
+
+/*
+ * Initialize token list.
+ */
+int GUTHTHILA_CALL
+guththila_tok_list_init(
+ guththila_tok_list_t * tok_list,
+ const axutil_env_t * env);
+
+/*
+ * Free the token list. Allocated tokens are not free.
+ */
+void GUTHTHILA_CALL
+guththila_tok_list_free(
+ guththila_tok_list_t * tok_list,
+ const axutil_env_t * env);
+
+/*
+ * Get a token from the list.
+ */
+guththila_token_t *
+GUTHTHILA_CALL guththila_tok_list_get_token(
+ guththila_tok_list_t * tok_list,
+ const axutil_env_t * env);
+
+/*
+ * Release a token to the token list.
+ */
+int GUTHTHILA_CALL
+guththila_tok_list_release_token(
+ guththila_tok_list_t * tok_list,
+ guththila_token_t * token,
+ const axutil_env_t * env);
+
+/*
+ * Free the tokens in the token list.
+ */
+void GUTHTHILA_CALL
+guththila_tok_list_free_data(
+ guththila_tok_list_t * tok_list,
+ const axutil_env_t * env);
+
+/*
+ * Grow the token list.
+ */
+int GUTHTHILA_CALL
+guththila_tok_list_grow(
+ guththila_tok_list_t * tok_list,
+ const axutil_env_t * env);
+
+/*
+ * Compare a token with a string.
+ * Return 0 if match.
+ */
+int GUTHTHILA_CALL
+guththila_tok_str_cmp(
+ guththila_token_t * tok,
+ guththila_char_t *str,
+ size_t str_len,
+ const axutil_env_t * env);
+
+/*
+ * Compare two tokens for string equalance
+ * Return 0 if match.
+ */
+int GUTHTHILA_CALL
+guththila_tok_tok_cmp(
+ guththila_token_t * tok1,
+ guththila_token_t * tok2,
+ const axutil_env_t * env);
+
+void GUTHTHILA_CALL
+guththila_set_token(
+ guththila_token_t* tok,
+ guththila_char_t* start,
+ short type,
+ int size,
+ int _start,
+ int last,
+ int ref,
+ const axutil_env_t* env);
+
+EXTERN_C_END()
+#endif
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/guththila/include/guththila_xml_writer.h b/guththila/include/guththila_xml_writer.h
new file mode 100644
index 0000000..afc5a26
--- /dev/null
+++ b/guththila/include/guththila_xml_writer.h
@@ -0,0 +1,507 @@
+
+/*
+ * 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.
+ */
+#ifndef GUTHTHILA_XML_WRITER_H
+#define GUTHTHILA_XML_WRITER_H
+
+#include <guththila_token.h>
+#include <guththila_defines.h>
+#include <guththila_buffer.h>
+#include <guththila.h>
+#include <axutil_utils.h>
+
+EXTERN_C_START()
+#define GUTHTHILA_XML_WRITER_TOKEN
+
+/*
+Design notes:-
+namesp member of guththila_xml_writer_s is populated with malloc created objects.
+Providing a list for this seems expensive because most of the times only few
+namespaces are present in a XML document.
+
+element member of guththila_xml_writer_s must be povided the list capablity. This
+is particularly important in very deep XML documents.
+*/
+typedef enum guththila_writer_type_s
+{
+ GUTHTHILA_WRITER_FILE = 1,
+ GUTHTHILA_WRITER_MEMORY
+} guththila_writer_type_t;
+
+typedef struct guththila_writer_s
+{
+ short type;
+ FILE *out_stream;
+ guththila_buffer_t *buffer;
+ int next;
+}
+guththila_writer_t;
+
+typedef enum guththila_writer_status_s
+{
+ /*Started writing a non empty element */
+ START = 1,
+ /*Started writing a empty element */
+ START_EMPTY,
+ /*We are in a position to begin wrting an element */
+ BEGINING
+} guththila_writer_status_t;
+
+/*Main structure which provides the writer capability*/
+typedef struct guththila_xml_writer_s
+{
+ guththila_stack_t element;
+ guththila_stack_t namesp;
+ guththila_writer_t *writer;
+#ifdef GUTHTHILA_XML_WRITER_TOKEN
+ guththila_tok_list_t tok_list;
+#endif
+ /* Type of this writer. Can be file writer or memory writer */
+ guththila_writer_type_t type;
+
+ FILE *out_stream;
+ guththila_buffer_t buffer;
+ guththila_writer_status_t status;
+ int next;
+} guththila_xml_writer_t;
+
+/*TODO: we need to came up with common implementation of followng two structures in writer and reader*/
+
+/*
+This is a private structure for keeping track of the elements. When we start to write an element this structure will be pop
+*/
+typedef struct guththila_xml_writer_element_s
+{
+#ifdef GUTHTHILA_XML_WRITER_TOKEN
+ guththila_token_t *prefix;
+ guththila_token_t *name;
+#else
+ guththila_char_t *prefix;
+ guththila_char_t *name;
+#endif
+ /* contains the number of the stack which holds the namespaces
+ for this element. When we close this element all the namespaces
+ that are below this should also must be closed */
+ int name_sp_stack_no;
+}
+guththila_xml_writer_element_t;
+
+typedef struct guththila_xml_writer_namesp_s
+{
+ /* These are double pointers because a single element may contain multple
+ namespace declarations */
+#ifdef GUTHTHILA_XML_WRITER_TOKEN
+ guththila_token_t **name;
+ guththila_token_t **uri;
+#else
+ guththila_char_t **name;
+ guththila_char_t **uri;
+#endif
+ int no; /*number of namespaces */
+ int size;
+}
+guththila_xml_writer_namesp_t;
+
+#define GUTHTHILA_XML_WRITER_NAMESP_DEF_SIZE 4
+
+/*Writer functions*/
+
+/*
+ * Create a writer which writes to a file.
+ * @param file_name name of the file
+ * @param env pointer to the environment
+ */
+GUTHTHILA_EXPORT guththila_xml_writer_t *GUTHTHILA_CALL
+guththila_create_xml_stream_writer(
+ char *file_name,
+ const axutil_env_t * env);
+
+/*
+ * Create a writer which writes to a memory buffer.
+ * @param env pointer to the environment
+ */
+GUTHTHILA_EXPORT guththila_xml_writer_t *GUTHTHILA_CALL
+guththila_create_xml_stream_writer_for_memory(
+ const axutil_env_t * env);
+
+/*
+ * Jus write what ever the content in the buffer. If the writer was in
+ * a start of a element it will close it.
+ * @param wr pointer to the writer
+ * @param buff buffer containing the data
+ * @param size size of the buffer
+ * @param env pointer to the environment
+ */
+GUTHTHILA_EXPORT int GUTHTHILA_CALL guththila_write_to_buffer(
+ guththila_xml_writer_t * wr,
+ char *buff,
+ int size,
+ const axutil_env_t * env);
+
+/*
+ * Write the name space with the given prifix and namespace.
+ * @param wr pointer to the writer
+ * @param prefix prefix of the namespace
+ * @param uri uri of the namespace
+ * @param env pointer to the environment
+ */
+GUTHTHILA_EXPORT int GUTHTHILA_CALL guththila_write_namespace(
+ guththila_xml_writer_t * wr,
+ char *prefix,
+ char *uri,
+ const axutil_env_t * env);
+
+/*
+ * Write the name space with the given prifix and namespace.
+ * @param wr pointer to the writer
+ * @param prefix prefix of the namespace
+ * @param uri uri of the namespace
+ * @param local_name name of the attribute
+ * @param value value of the attribute
+ * @param env pointer to the environment
+ */
+GUTHTHILA_EXPORT int GUTHTHILA_CALL
+guththila_do_write_attribute_with_prefix_and_namespace(
+ guththila_xml_writer_t * wr,
+ char *prefix,
+ char *uri,
+ char *local_name,
+ char *value,
+ const axutil_env_t * env);
+
+
+/*
+ * Write the start document element with the xml version and encoding.
+ * @param wr pointer to the writer
+ * @param env pointer to the environment
+ * @param encoding encoding of the XML.
+ * @param version xml version
+ */
+GUTHTHILA_EXPORT int GUTHTHILA_CALL guththila_write_start_document(
+ guththila_xml_writer_t * wr,
+ const axutil_env_t * env,
+ char *encoding,
+ char *version);
+
+/*
+ * Write the start element.
+ * @param wr pointer to the writer
+ * @param name name of the element
+ * @param env pointer to the environment
+ */
+GUTHTHILA_EXPORT int GUTHTHILA_CALL guththila_write_start_element(
+ guththila_xml_writer_t * wr,
+ char *name,
+ const axutil_env_t * env);
+
+/*
+ * Write the end element.
+ * @param wr pointer to the writer
+ * @param env pointer to the environment
+ */
+GUTHTHILA_EXPORT int GUTHTHILA_CALL guththila_write_end_element(
+ guththila_xml_writer_t * wr,
+ const axutil_env_t * env);
+
+/*
+ * Not implemented.
+ * @param wr pointer to the writer
+ * @param env pointer to the environment
+ */
+GUTHTHILA_EXPORT int GUTHTHILA_CALL guththila_close(
+ guththila_xml_writer_t * wr,
+ const axutil_env_t * env);
+
+/*
+ * Write the text content of a element.
+ * @param wr pointer to the writer
+ * @param buff character string
+ * @param env pointer to the environment
+ */
+GUTHTHILA_EXPORT int GUTHTHILA_CALL guththila_write_characters(
+ guththila_xml_writer_t * wr,
+ char *buff,
+ const axutil_env_t * env);
+
+/*
+ * Write comment with the given text data.
+ * @param wr pointer to the writer
+ * @param buff character string
+ * @param env pointer to the environment
+ */
+GUTHTHILA_EXPORT int GUTHTHILA_CALL guththila_write_comment(
+ guththila_xml_writer_t * wr,
+ char *buff,
+ const axutil_env_t * env);
+
+/*
+ * Write scape character.
+ * @param wr pointer to the writer
+ * @param buff character string
+ * @param env pointer to the environment
+ */
+GUTHTHILA_EXPORT int GUTHTHILA_CALL guththila_write_escape_character(
+ guththila_xml_writer_t * wr,
+ char *buff,
+ const axutil_env_t * env);
+
+/*
+ * Start to write an empty element with the given name.
+ * @param wr pointer to the writer
+ * @param name name of the element
+ * @param env pointer to the environment
+ */
+GUTHTHILA_EXPORT int GUTHTHILA_CALL guththila_write_empty_element(
+ guththila_xml_writer_t * wr,
+ char *name,
+ const axutil_env_t * env);
+
+/*
+ * Write a defualt namespace.
+ * @param wr pointer to the writer
+ * @param uri uri of the namespace
+ * @param env pointer to the environment
+ */
+GUTHTHILA_EXPORT int GUTHTHILA_CALL guththila_write_default_namespace(
+ guththila_xml_writer_t * wr,
+ char *uri,
+ const axutil_env_t * env);
+
+/*
+ * Write a attribute with the given name and value.
+ * @param wr pointer to the writer
+ * @param localname name of the attribute
+ * @param value value of the attribute
+ * @param env pointer to the environment
+ */
+GUTHTHILA_EXPORT int GUTHTHILA_CALL guththila_write_attribute(
+ guththila_xml_writer_t * wr,
+ char *localname,
+ char *value,
+ const axutil_env_t * env);
+
+/*
+ * Write a attribute with the given name and value and namespace.
+ * @param wr pointer to the writer
+ * @param prefix prefix of the attribute
+ * @param namespace_uri uri of the namespace
+ * @param localname name of the attribute
+ * @param value value of the attribute
+ * @param env pointer to the environment
+ */
+GUTHTHILA_EXPORT int GUTHTHILA_CALL
+guththila_write_attribute_with_prefix_and_namespace(
+ guththila_xml_writer_t * wr,
+ char *prefix,
+ char *namespace_uri,
+ char *localname,
+ char *value,
+ const axutil_env_t * env);
+
+/*
+ * Write a attribute with the given name, value and prefix. If the prefix
+ * is not defined previously as a namespace this method will fail.
+ * @param wr pointer to the writer
+ * @param prefix prefix of the attribute
+ * @param localname name of the attribute
+ * @param value value of the attribute
+ * @param env pointer to the environment
+ */
+GUTHTHILA_EXPORT int GUTHTHILA_CALL guththila_write_attribute_with_prefix(
+ guththila_xml_writer_t * wr,
+ char *prefix,
+ char *localname,
+ char *value,
+ const axutil_env_t * env);
+
+/*
+ * Write a attribute with the given name, value and namespace uri.
+ * If the namespace is not defined previously as a namespace this
+ * method will fail. The prefix corresponding to the namespace uri
+ * will be used.
+ * @param wr pointer to the writer
+ * @param namesp namespace uri
+ * @param localname name of the attribute
+ * @param value value of the attribute
+ * @param env pointer to the environment
+ */
+GUTHTHILA_EXPORT int GUTHTHILA_CALL guththila_write_attribute_with_namespace(
+ guththila_xml_writer_t * wr,
+ char *namesp,
+ char *localname,
+ char *value,
+ const axutil_env_t * env);
+
+/*
+ * Write a start element with prefix and namespace. If the namespace is not
+ * defined previoully new namespace will be written.
+ * @param wr pointer to the writer
+ * @param prefix prefix of the attribute
+ * @param namespace_uri uri
+ * @param localname name of the attribute
+ * @param env pointer to the environment
+ */
+GUTHTHILA_EXPORT int GUTHTHILA_CALL
+guththila_write_start_element_with_prefix_and_namespace(
+ guththila_xml_writer_t * wr,
+ char *prefix,
+ char *namespace_uri,
+ char *local_name,
+ const axutil_env_t * env);
+
+/*
+ * Write a start element with the namespace. If the namespace is not
+ * defined previously method will fail.
+ * @param wr pointer to the writer
+ * @param namespace_uri uri
+ * @param localname name of the attribute
+ * @param env pointer to the environment
+ */
+GUTHTHILA_EXPORT int GUTHTHILA_CALL
+guththila_write_start_element_with_namespace(
+ guththila_xml_writer_t * wr,
+ char *namespace_uri,
+ char *local_name,
+ const axutil_env_t * env);
+
+/*
+ * Write a start element with the prefix. If the prefix is not
+ * defined previously method will fail.
+ * @param wr pointer to the writer
+ * @param namespace_uri uri
+ * @param localname name of the attribute
+ * @param env pointer to the environment
+ */
+GUTHTHILA_EXPORT int GUTHTHILA_CALL
+guththila_write_start_element_with_prefix(
+ guththila_xml_writer_t * wr,
+ char *prefix,
+ char *local_name,
+ const axutil_env_t * env);
+
+/*
+ * Write a empty element with prefix and namespace. If the namespace is not
+ * defined previoully new namespace will be written.
+ * @param wr pointer to the writer
+ * @param prefix prefix of the attribute
+ * @param namespace_uri uri
+ * @param localname name of the attribute
+ * @param env pointer to the environment
+ */
+GUTHTHILA_EXPORT int GUTHTHILA_CALL
+guththila_write_empty_element_with_prefix_and_namespace(
+ guththila_xml_writer_t * wr,
+ char *prefix,
+ char *namespace_uri,
+ char *local_name,
+ const axutil_env_t * env);
+
+/*
+ * Write a empty element with the namespace. If the namespace is not
+ * defined previously method will fail.
+ * @param wr pointer to the writer
+ * @param namespace_uri uri
+ * @param localname name of the attribute
+ * @param env pointer to the environment
+ */
+GUTHTHILA_EXPORT int GUTHTHILA_CALL
+guththila_write_empty_element_with_namespace(
+ guththila_xml_writer_t * wr,
+ char *namespace_uri,
+ char *local_name,
+ const axutil_env_t * env);
+
+/*
+ * Write a empty element with the prefix. If the prefix is not
+ * defined previously method will fail.
+ * @param wr pointer to the writer
+ * @param namespace_uri uri
+ * @param localname name of the attribute
+ * @param env pointer to the environment
+ */
+GUTHTHILA_EXPORT int GUTHTHILA_CALL
+guththila_write_empty_element_with_prefix(
+ guththila_xml_writer_t * wr,
+ char *prefix,
+ char *local_name,
+ const axutil_env_t * env);
+
+/*
+ * Close all the elements that were started by writing the end elements.
+ * @param wr pointer to the writer
+ * @param env pointer to the environment
+ */
+GUTHTHILA_EXPORT int GUTHTHILA_CALL guththila_write_end_document(
+ guththila_xml_writer_t * wr,
+ const axutil_env_t * env);
+/*
+ * Write a new element with the name, then write the characters as text,
+ * then close the element and write a new line.
+ * @param wr pointer to the writer
+ * @element_name name of the element
+ * @characters text of the new element
+ * @param env pointer to the environment
+ */
+GUTHTHILA_EXPORT int GUTHTHILA_CALL guththila_write_line(
+ guththila_xml_writer_t * wr,
+ char *element_name,
+ char *characters,
+ const axutil_env_t * env);
+
+/*
+ * Get the memory buffer that is written.
+ * @param wr pointer to the writer
+ * @param env pointer to the environment
+ * @return memory buffer
+ */
+GUTHTHILA_EXPORT char *GUTHTHILA_CALL guththila_get_memory_buffer(
+ guththila_xml_writer_t * wr,
+ const axutil_env_t * env);
+
+/*
+ * Get the size of the memory buffer.
+ * @param wr pointer to the writer
+ * @param env pointer to the environment
+ * @return size of the buffer
+ */
+GUTHTHILA_EXPORT unsigned int GUTHTHILA_CALL
+guththila_get_memory_buffer_size(
+ guththila_xml_writer_t * wr,
+ const axutil_env_t * env);
+
+/*
+ * Free the writer.
+ * @param wr pointer to the writer
+ * @param env pointer to the environment
+ */
+GUTHTHILA_EXPORT void GUTHTHILA_CALL guththila_xml_writer_free(
+ guththila_xml_writer_t * wr,
+ const axutil_env_t * env);
+/*
+ * Get the prefix for the namespace.
+ * @param wr pointer to the writer
+ * @namespace namespace uri
+ * @param env pointer to the environment
+ * @return prefix for the namspace uri
+ */
+GUTHTHILA_EXPORT char *GUTHTHILA_CALL guththila_get_prefix_for_namespace(
+ guththila_xml_writer_t * wr,
+ char *namespace,
+ const axutil_env_t * env);
+
+EXTERN_C_END()
+#endif