You are viewing a plain text version of this content. The canonical link for it is here.
Posted to rampart-dev@ws.apache.org by pi...@apache.org on 2007/09/06 12:49:17 UTC

svn commit: r573215 [10/22] - in /webservices/rampart/tags/c/0.90: ./ build/ build/linux/ build/win32/ include/ samples/ samples/authn_provider/ samples/callback/ samples/callback/htpasswd_callback/ samples/client/ samples/client/sec_echo/ samples/clie...

Added: webservices/rampart/tags/c/0.90/src/omxmlsec/asym_ctx.c
URL: http://svn.apache.org/viewvc/webservices/rampart/tags/c/0.90/src/omxmlsec/asym_ctx.c?rev=573215&view=auto
==============================================================================
--- webservices/rampart/tags/c/0.90/src/omxmlsec/asym_ctx.c (added)
+++ webservices/rampart/tags/c/0.90/src/omxmlsec/asym_ctx.c Thu Sep  6 03:48:44 2007
@@ -0,0 +1,344 @@
+/*
+ * 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 <stdio.h>
+#include <axis2_util.h>
+#include <oxs_asym_ctx.h>
+#include <oxs_x509_cert.h>
+#include <oxs_error.h>
+
+struct oxs_asym_ctx_t
+{
+    axis2_char_t *file_name;
+    axis2_char_t *pem_buf;
+    axis2_char_t *password;
+    axis2_char_t *algorithm;
+    axis2_char_t *st_ref_pattern;
+    oxs_asym_ctx_operation_t operation;
+    oxs_asym_ctx_format_t format;
+    oxs_x509_cert_t *certificate;
+    openssl_pkey_t *private_key;
+
+};
+
+
+/*Public functions*/
+
+AXIS2_EXTERN
+axis2_char_t *AXIS2_CALL
+oxs_asym_ctx_get_file_name(
+    const oxs_asym_ctx_t *asym_ctx,
+    const axutil_env_t *env)
+{
+    return asym_ctx->file_name;
+}
+
+AXIS2_EXTERN
+axis2_char_t *AXIS2_CALL
+oxs_asym_ctx_get_pem_buf(
+    const oxs_asym_ctx_t *asym_ctx,
+    const axutil_env_t *env)
+{
+    return asym_ctx->pem_buf;
+}
+AXIS2_EXTERN
+axis2_char_t *AXIS2_CALL
+oxs_asym_ctx_get_password(
+    const oxs_asym_ctx_t *asym_ctx,
+    const axutil_env_t *env)
+{
+    return asym_ctx->password;
+}
+AXIS2_EXTERN
+oxs_asym_ctx_format_t AXIS2_CALL
+oxs_asym_ctx_get_format(
+    const oxs_asym_ctx_t *asym_ctx,
+    const axutil_env_t *env)
+{
+    return asym_ctx->format;
+}
+
+AXIS2_EXTERN
+axis2_char_t *AXIS2_CALL
+oxs_asym_ctx_get_algorithm(
+    const oxs_asym_ctx_t *asym_ctx,
+    const axutil_env_t *env)
+{
+    return asym_ctx->algorithm;
+}
+
+AXIS2_EXTERN
+axis2_char_t *AXIS2_CALL
+oxs_asym_ctx_get_st_ref_pattern(
+    const oxs_asym_ctx_t *asym_ctx,
+    const axutil_env_t *env)
+{
+    return asym_ctx->st_ref_pattern;
+}
+
+AXIS2_EXTERN
+oxs_asym_ctx_operation_t AXIS2_CALL
+oxs_asym_ctx_get_operation(
+    const oxs_asym_ctx_t *asym_ctx,
+    const axutil_env_t *env)
+{
+    return asym_ctx->operation;
+}
+
+AXIS2_EXTERN
+openssl_pkey_t *AXIS2_CALL
+oxs_asym_ctx_get_private_key(
+    const oxs_asym_ctx_t *asym_ctx,
+    const axutil_env_t *env)
+{
+
+    return asym_ctx->private_key;
+}
+
+AXIS2_EXTERN
+oxs_x509_cert_t *AXIS2_CALL
+oxs_asym_ctx_get_certificate(
+    const oxs_asym_ctx_t *asym_ctx,
+    const axutil_env_t *env)
+{
+
+    return asym_ctx->certificate;
+}
+
+AXIS2_EXTERN
+axis2_status_t AXIS2_CALL
+oxs_asym_ctx_set_file_name(
+    oxs_asym_ctx_t *asym_ctx,
+    const axutil_env_t *env,
+    axis2_char_t *file_name)
+{
+
+    if (asym_ctx->file_name)
+    {
+        AXIS2_FREE(env->allocator, asym_ctx->file_name);
+        asym_ctx->file_name = NULL;
+    }
+    asym_ctx->file_name = axutil_strdup(env, file_name);
+    return AXIS2_SUCCESS;
+}
+
+AXIS2_EXTERN
+axis2_status_t AXIS2_CALL
+oxs_asym_ctx_set_pem_buf(
+    oxs_asym_ctx_t *asym_ctx,
+    const axutil_env_t *env,
+    axis2_char_t *pem_buf)
+{
+
+    if (asym_ctx->pem_buf)
+    {
+        AXIS2_FREE(env->allocator, asym_ctx->pem_buf);
+        asym_ctx->pem_buf = NULL;
+    }
+    asym_ctx->pem_buf = axutil_strdup(env, pem_buf);
+    return AXIS2_SUCCESS;
+}
+
+AXIS2_EXTERN
+axis2_status_t AXIS2_CALL
+oxs_asym_ctx_set_password(
+    oxs_asym_ctx_t *asym_ctx,
+    const axutil_env_t *env,
+    axis2_char_t *password)
+{
+
+    if (asym_ctx->password)
+    {
+        AXIS2_FREE(env->allocator, asym_ctx->password);
+        asym_ctx->password = NULL;
+    }
+    asym_ctx->password = axutil_strdup(env, password);
+    return AXIS2_SUCCESS;
+}
+
+AXIS2_EXTERN
+axis2_status_t AXIS2_CALL
+oxs_asym_ctx_set_format(
+    oxs_asym_ctx_t *asym_ctx,
+    const axutil_env_t *env,
+    oxs_asym_ctx_format_t format)
+{
+
+    asym_ctx->format = format;
+    return AXIS2_SUCCESS;
+}
+
+AXIS2_EXTERN
+axis2_status_t AXIS2_CALL
+oxs_asym_ctx_set_algorithm(
+    oxs_asym_ctx_t *asym_ctx,
+    const axutil_env_t *env,
+    axis2_char_t *algorithm)
+{
+
+    if (asym_ctx->algorithm)
+    {
+        AXIS2_FREE(env->allocator, asym_ctx->algorithm);
+        asym_ctx->algorithm = NULL;
+    }
+    asym_ctx->algorithm = axutil_strdup(env, algorithm);
+    return AXIS2_SUCCESS;
+}
+
+AXIS2_EXTERN
+axis2_status_t AXIS2_CALL
+oxs_asym_ctx_set_st_ref_pattern(
+    oxs_asym_ctx_t *asym_ctx,
+    const axutil_env_t *env,
+    axis2_char_t *st_ref_pattern)
+{
+    if (asym_ctx->st_ref_pattern)
+    {
+        AXIS2_FREE(env->allocator, asym_ctx->st_ref_pattern);
+        asym_ctx->st_ref_pattern = NULL;
+    }
+    asym_ctx->st_ref_pattern = axutil_strdup(env, st_ref_pattern);
+    return AXIS2_SUCCESS;
+}
+
+AXIS2_EXTERN
+axis2_status_t AXIS2_CALL
+oxs_asym_ctx_set_operation(
+    oxs_asym_ctx_t *asym_ctx,
+    const axutil_env_t *env,
+    oxs_asym_ctx_operation_t operation)
+{
+
+    asym_ctx->operation = operation;
+    return AXIS2_SUCCESS;
+}
+
+
+AXIS2_EXTERN
+axis2_status_t AXIS2_CALL
+oxs_asym_ctx_set_certificate(
+    oxs_asym_ctx_t *asym_ctx,
+    const axutil_env_t *env,
+    oxs_x509_cert_t *certificate)
+{
+
+    if (asym_ctx->certificate)
+    {
+        oxs_x509_cert_free(asym_ctx->certificate, env);
+        asym_ctx->certificate = NULL;
+    }
+    asym_ctx->certificate = certificate;
+    return AXIS2_SUCCESS;
+}
+
+AXIS2_EXTERN
+axis2_status_t AXIS2_CALL
+oxs_asym_ctx_set_private_key(
+    oxs_asym_ctx_t *asym_ctx,
+    const axutil_env_t *env,
+    openssl_pkey_t *private_key)
+{
+
+    if (asym_ctx->private_key)
+    {
+        /*openssl_pkey_free(asym_ctx->private_key, env);*/
+        asym_ctx->private_key = NULL;
+    }
+    asym_ctx->private_key = private_key;
+    return AXIS2_SUCCESS;
+}
+
+
+AXIS2_EXTERN
+oxs_asym_ctx_t *AXIS2_CALL
+oxs_asym_ctx_create(const axutil_env_t *env)
+{
+    oxs_asym_ctx_t *asym_ctx = NULL;
+
+    AXIS2_ENV_CHECK(env, NULL);
+
+    asym_ctx = AXIS2_MALLOC(env->allocator, sizeof(oxs_asym_ctx_t));
+    if (!asym_ctx)
+    {
+        AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE);
+        return NULL;
+    }
+
+    asym_ctx->file_name= NULL;
+    asym_ctx->pem_buf= NULL;
+    asym_ctx->password= NULL;
+    asym_ctx->format= -1;
+    asym_ctx->algorithm = NULL;
+    asym_ctx->st_ref_pattern = NULL;
+    asym_ctx->operation = -1;
+    asym_ctx->certificate = NULL;
+
+    return asym_ctx;
+}
+
+
+AXIS2_EXTERN
+axis2_status_t AXIS2_CALL
+oxs_asym_ctx_free(oxs_asym_ctx_t *asym_ctx,
+                  const axutil_env_t *env)
+{
+
+    AXIS2_ENV_CHECK(env, AXIS2_FAILURE);
+
+    if (asym_ctx->file_name)
+    {
+        AXIS2_FREE(env->allocator, asym_ctx->file_name);
+        asym_ctx->file_name = NULL;
+    }
+
+    if (asym_ctx->pem_buf)
+    {
+        AXIS2_FREE(env->allocator, asym_ctx->pem_buf);
+        asym_ctx->pem_buf = NULL;
+    }
+
+    if (asym_ctx->password)
+    {
+        AXIS2_FREE(env->allocator, asym_ctx->password);
+        asym_ctx->password = NULL;
+    }
+
+    if (asym_ctx->algorithm)
+    {
+        AXIS2_FREE(env->allocator, asym_ctx->algorithm);
+        asym_ctx->algorithm = NULL;
+    }
+
+    if (asym_ctx->st_ref_pattern)
+    {
+        AXIS2_FREE(env->allocator, asym_ctx->st_ref_pattern);
+        asym_ctx->st_ref_pattern = NULL;
+    }
+
+    if (asym_ctx->certificate)
+    {
+        oxs_x509_cert_free(asym_ctx->certificate, env);
+        asym_ctx->certificate = NULL;
+    }
+
+    AXIS2_FREE(env->allocator,  asym_ctx);
+    asym_ctx = NULL;
+
+    return AXIS2_SUCCESS;
+}
+
+

Added: webservices/rampart/tags/c/0.90/src/omxmlsec/axiom.c
URL: http://svn.apache.org/viewvc/webservices/rampart/tags/c/0.90/src/omxmlsec/axiom.c?rev=573215&view=auto
==============================================================================
--- webservices/rampart/tags/c/0.90/src/omxmlsec/axiom.c (added)
+++ webservices/rampart/tags/c/0.90/src/omxmlsec/axiom.c Thu Sep  6 03:48:44 2007
@@ -0,0 +1,321 @@
+/*
+ * 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 <stdio.h>
+#include <axis2_util.h>
+#include <oxs_constants.h>
+#include <oxs_error.h>
+#include <oxs_axiom.h>
+#include <axiom_node.h>
+#include <axiom_namespace.h>
+#include <axiom_attribute.h>
+#include <axiom_element.h>
+#include <axiom_document.h>
+#include <axiom_stax_builder.h>
+#include <axiom_util.h>
+
+AXIS2_EXTERN axis2_status_t AXIS2_CALL
+oxs_axiom_add_attribute(const axutil_env_t *env,
+                        axiom_node_t* node,
+                        axis2_char_t* attribute_ns,
+                        axis2_char_t* attribute_ns_uri,
+                        axis2_char_t* attribute,
+                        axis2_char_t* value)
+{
+    axiom_attribute_t *attr = NULL;
+    axiom_element_t *ele = NULL;
+    axis2_status_t status = AXIS2_FAILURE;
+    axiom_namespace_t *ns = NULL;
+
+    ns =  axiom_namespace_create(env, attribute_ns_uri, attribute_ns);
+
+    ele =  axiom_node_get_data_element(node, env);
+    attr =  axiom_attribute_create(env, attribute , value, ns);
+    status = axiom_element_add_attribute(ele, env, attr, node);
+
+    return status;
+}
+
+AXIS2_EXTERN int AXIS2_CALL
+oxs_axiom_get_number_of_children_with_qname(const axutil_env_t *env,
+        axiom_node_t* parent,
+        axis2_char_t* local_name,
+        axis2_char_t* ns_uri,
+        axis2_char_t* prefix)
+{
+
+    axutil_qname_t *qname = NULL;
+    axiom_element_t *parent_ele = NULL;
+    axiom_children_qname_iterator_t *qname_iter = NULL;
+    axiom_node_t *temp_node = NULL;
+    int counter = 0;
+
+    qname = axutil_qname_create(env, local_name, ns_uri, prefix);
+    parent_ele = axiom_node_get_data_element(parent, env);
+    if (!parent_ele)
+    {
+        oxs_error(env, ERROR_LOCATION, OXS_ERROR_INVALID_DATA,
+                  "Cannot find %s element", local_name);
+        return -1;
+    }
+
+    qname_iter = axiom_element_get_children_with_qname(parent_ele, env, qname, parent);
+    while (AXIS2_TRUE == axiom_children_qname_iterator_has_next(qname_iter , env))
+    {
+
+        counter++;
+        temp_node = axiom_children_qname_iterator_next(qname_iter, env);
+    }
+
+    return counter;
+}
+
+/**
+ * Traverse thru the node and its children. Check if the localname is equal to the given name
+ * */
+AXIS2_EXTERN axiom_node_t* AXIS2_CALL
+oxs_axiom_get_node_by_local_name(const axutil_env_t *env,
+                                 axiom_node_t *node,
+                                 axis2_char_t *local_name)
+{
+    axis2_char_t *temp_name = NULL;
+
+    if(!node){return NULL;}
+
+    if(axiom_node_get_node_type(node, env) != AXIOM_ELEMENT){return NULL;}
+
+    temp_name = axiom_util_get_localname(node, env);
+    AXIS2_LOG_INFO(env->log, "[rampart][axiom] Checking node %s for %s", temp_name, local_name );
+
+    if(0 == axutil_strcmp(temp_name, local_name) ){
+        /*Gottcha.. return this node*/
+        return node;
+    }else{
+        /*Doesn't match? Get the first child*/
+        axiom_node_t *temp_node = NULL;
+
+        temp_node = axiom_node_get_first_element(node, env);
+        while (temp_node)
+        {
+            axiom_node_t *res_node = NULL;
+            res_node = oxs_axiom_get_node_by_local_name(env, temp_node, local_name);
+            if(res_node){
+                return res_node;
+            }
+            temp_node = axiom_node_get_next_sibling(temp_node, env);
+        }
+
+    }
+    return NULL;
+}
+
+/**
+ * Traverse thru the node and its children. Check if the id attribute is equal to the given value
+ * */
+AXIS2_EXTERN axiom_node_t* AXIS2_CALL
+oxs_axiom_get_node_by_id(const axutil_env_t *env,
+                         axiom_node_t *node,
+                         axis2_char_t *attr,
+                         axis2_char_t *val)
+{
+    axis2_char_t *attribute_value = NULL;
+    axis2_char_t *localname = NULL;
+
+    if(!node){return NULL;}
+
+    if(axiom_node_get_node_type(node, env) != AXIOM_ELEMENT){return NULL;}
+
+    localname = axiom_util_get_localname(node, env);
+    /*AXIS2_LOG_INFO(env->log, "[rampart][axiom] Checking node %s for the attribute %s with value = %s", localname, attr, val);*/
+
+    attribute_value = oxs_axiom_get_attribute_value_of_node_by_name(env, node, attr);
+    if(0 == axutil_strcmp(val, attribute_value) ){
+        /*Gottcha.. return this node*/
+        return node;
+    }else{
+        /*Doesn't match? Get the first child*/
+        axiom_node_t *temp_node = NULL;
+
+        temp_node = axiom_node_get_first_element(node, env);
+        while (temp_node)
+        {
+            axiom_node_t *res_node = NULL;
+            res_node = oxs_axiom_get_node_by_id(env, temp_node, attr, val);
+            if(res_node){
+                return res_node;
+            }
+            temp_node = axiom_node_get_next_sibling(temp_node, env);
+        }
+
+    }
+    return NULL;
+}
+
+
+AXIS2_EXTERN axis2_char_t* AXIS2_CALL
+oxs_axiom_get_attribute_value_of_node_by_name(const axutil_env_t *env,
+        axiom_node_t *node,
+        axis2_char_t *attribute_name)
+{
+    axis2_char_t *attribute_value = NULL;
+    axiom_element_t *ele = NULL;
+
+    ele = axiom_node_get_data_element(node, env);
+    attribute_value = axiom_element_get_attribute_value_by_name(ele, env, attribute_name);
+
+    return attribute_value;
+}
+
+AXIS2_EXTERN axiom_node_t* AXIS2_CALL
+oxs_axiom_get_first_child_node_by_name(const axutil_env_t *env,
+                                       axiom_node_t* parent,
+                                       axis2_char_t* local_name,
+                                       axis2_char_t* ns_uri,
+                                       axis2_char_t* prefix)
+{
+    axutil_qname_t *qname = NULL;
+    axiom_node_t *node = NULL;
+    axiom_element_t *parent_ele = NULL;
+    axiom_element_t *ele = NULL;
+    axis2_char_t *parent_name = NULL;
+
+    qname = axutil_qname_create(env, local_name, ns_uri, prefix);
+    parent_ele = axiom_node_get_data_element(parent, env);
+    if (!parent_ele)
+    {
+        oxs_error(env, ERROR_LOCATION, OXS_ERROR_INVALID_DATA,
+                  "Cannot find %s element", local_name);
+        return NULL;
+    }
+    /*Get the child*/
+    ele = axiom_element_get_first_child_with_qname(parent_ele, env, qname, parent, &node);
+
+    axutil_qname_free(qname, env);
+    qname = NULL;
+
+    parent_name = axiom_node_to_string(parent, env);
+    if (!node)
+    {
+        oxs_error(env, ERROR_LOCATION, OXS_ERROR_INVALID_DATA,
+                  "Cannot find child %s of %s", local_name, parent_name);
+        return NULL;
+    }
+    return node;
+}
+
+
+AXIS2_EXTERN axis2_char_t* AXIS2_CALL
+oxs_axiom_get_node_content(const axutil_env_t *env, axiom_node_t* node)
+{
+    axiom_element_t *ele = NULL;
+    axis2_char_t *content = NULL;
+
+    ele = axiom_node_get_data_element(node, env);
+    if (!ele) return NULL;
+
+    content = axiom_element_get_text(ele, env, node);
+    if (!content) return NULL;
+
+    return content;
+}
+
+AXIS2_EXTERN axiom_node_t *AXIS2_CALL
+oxs_axiom_deserialize_node(const axutil_env_t *env,  axis2_char_t* buffer)
+{
+
+    axiom_document_t *doc = NULL;
+    axiom_stax_builder_t *builder = NULL;
+    axiom_xml_reader_t *reader = NULL;
+    axiom_node_t *node = NULL;
+
+    if (!buffer)
+    {
+        oxs_error(env, ERROR_LOCATION, OXS_ERROR_INVALID_DATA,
+                  "buffer is NULL");
+        return NULL;
+    }
+    reader = axiom_xml_reader_create_for_memory(env,
+             (void*)buffer, axutil_strlen(buffer), "utf-8", AXIS2_XML_PARSER_TYPE_BUFFER);
+
+    if (!reader)
+    {
+        oxs_error(env, ERROR_LOCATION, OXS_ERROR_INVALID_DATA,
+                  "axiom_xml_reader is NULL");
+        return NULL;
+    }
+
+    builder = axiom_stax_builder_create(env, reader);
+    if (!builder)
+    {
+        oxs_error(env, ERROR_LOCATION, OXS_ERROR_INVALID_DATA,
+                  "axiom_stax_builder is NULL");
+        return NULL;
+    }
+
+    doc = axiom_document_create(env, NULL, builder);
+    if (!doc)
+    {
+        oxs_error(env, ERROR_LOCATION, OXS_ERROR_INVALID_DATA,
+                  "axiom_document is NULL");
+        return NULL;
+    }
+    node = axiom_document_build_all(doc, env);
+    if (!node)
+    {
+        oxs_error(env, ERROR_LOCATION, OXS_ERROR_INVALID_DATA,
+                  "Building node failed");
+        return NULL;
+    }
+
+    return node;
+}
+
+AXIS2_EXTERN axis2_status_t AXIS2_CALL
+oxs_axiom_check_node_name(const axutil_env_t *env, axiom_node_t* node, axis2_char_t* name, axis2_char_t* ns)
+{
+    int ret_name, ret_ns;
+    axiom_element_t * ele = NULL;
+    axis2_char_t* namestr = NULL;
+    axis2_char_t* ns_str = NULL;
+    axutil_qname_t* qname = NULL;
+
+    ele = axiom_node_get_data_element(node, env);
+    qname = axiom_element_get_qname(ele, env, node);
+
+    namestr = axutil_qname_get_localpart(qname, env);
+    ret_name =  axutil_strcmp(namestr, name) ;
+
+
+    if (ret_name < 0) return 0;
+
+    if (ns)
+    {
+        ns_str = axutil_qname_get_uri(qname, env);
+        ret_ns =  axutil_strcmp(ns_str, ns) ;
+        if (ret_ns < 0) return AXIS2_FAILURE;
+        else   return AXIS2_SUCCESS;
+
+    }
+    else
+    {
+        return AXIS2_SUCCESS;
+    }
+
+
+}
+

Added: webservices/rampart/tags/c/0.90/src/omxmlsec/axis2_utils.c
URL: http://svn.apache.org/viewvc/webservices/rampart/tags/c/0.90/src/omxmlsec/axis2_utils.c?rev=573215&view=auto
==============================================================================
--- webservices/rampart/tags/c/0.90/src/omxmlsec/axis2_utils.c (added)
+++ webservices/rampart/tags/c/0.90/src/omxmlsec/axis2_utils.c Thu Sep  6 03:48:44 2007
@@ -0,0 +1,56 @@
+/*
+ * 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 <stdio.h>
+#include <axis2_util.h>
+#include <oxs_axis2_utils.h>
+#if 0
+AXIS2_EXTERN oxs_buffer_t * AXIS2_CALL  oxs_base64_decode(axutil_env_t *env,
+        oxs_buffer_t *coded_buf)
+{
+    axis2_char_t *plain_str = NULL;/* Here plain can be binary sometimes */
+    oxs_buffer_t *out_buf = NULL;
+    int  ret, length;
+
+    length =  axutil_base64_decode_len((char*)(oxs_buffer_get_data(coded_buf, env)));
+    plain_str = AXIS2_MALLOC(env->allocator, axutil_base64_decode_len((char*)(oxs_buffer_get_data(coded_buf, env))));
+    ret =  axutil_base64_decode(plain_str, (char*)(oxs_buffer_get_data(coded_buf, env)));
+    if (ret < 0) return NULL;
+    out_buf = oxs_string_to_buffer(env, plain_str);
+    return out_buf;
+}
+
+AXIS2_EXTERN oxs_buffer_t * AXIS2_CALL  oxs_base64_encode(axutil_env_t *env,
+        oxs_buffer_t *plain_buf)
+{
+    axis2_char_t *encoded_str = NULL;
+    oxs_buffer_t *out_buf = NULL;
+
+    int ret;
+
+    encoded_str = AXIS2_MALLOC(env->allocator, (unsigned int)axutil_base64_encode_len(axutil_strlen((char*)(plain_buf->data))));
+
+    ret =  axutil_base64_encode(encoded_str, (char*)(plain_buf->data), plain_buf->size);
+    if (ret < 0) return NULL;
+
+    /*Set to the output buffer */
+
+    out_buf = oxs_string_to_buffer(env, encoded_str);
+    return out_buf;
+}
+#endif
+

Added: webservices/rampart/tags/c/0.90/src/omxmlsec/buffer.c
URL: http://svn.apache.org/viewvc/webservices/rampart/tags/c/0.90/src/omxmlsec/buffer.c?rev=573215&view=auto
==============================================================================
--- webservices/rampart/tags/c/0.90/src/omxmlsec/buffer.c (added)
+++ webservices/rampart/tags/c/0.90/src/omxmlsec/buffer.c Thu Sep  6 03:48:44 2007
@@ -0,0 +1,431 @@
+/*
+ * 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 <axis2_defines.h>
+#include <stdio.h>
+#include <axis2_util.h>
+#include <oxs_constants.h>
+#include <oxs_buffer.h>
+#include <oxs_axiom.h>
+#include <oxs_error.h>
+
+
+
+struct oxs_buffer
+{
+    unsigned char* data;
+    unsigned int size;
+    unsigned int max_size;
+    oxs_AllocMode alloc_mode;
+};
+
+
+/******************** end of function headers *****************/
+
+AXIS2_EXTERN oxs_buffer_t *AXIS2_CALL
+oxs_buffer_create(const axutil_env_t *env)
+{
+    oxs_buffer_t *buffer = NULL;
+    axis2_status_t status = AXIS2_FAILURE;
+
+    AXIS2_ENV_CHECK(env, NULL);
+
+    buffer = (oxs_buffer_t*)AXIS2_MALLOC(env->allocator, sizeof(oxs_buffer_t));
+    if (!buffer)
+    {
+        AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE);
+        return NULL;
+    }
+
+    buffer->data = NULL;
+    buffer->size = 0;
+    buffer->max_size = 0;
+    buffer->alloc_mode = oxs_alloc_mode_double;
+
+    status = oxs_buffer_set_max_size(buffer, env, OXS_BUFFER_INITIAL_SIZE);
+    if (status == AXIS2_FAILURE)
+    {
+        oxs_error(env, ERROR_LOCATION, OXS_ERROR_DEFAULT,
+                  "oxs_buffer_set_max_size");
+        return NULL;
+    }
+
+    return buffer;
+
+}
+
+axis2_status_t AXIS2_CALL
+oxs_buffer_free(
+    oxs_buffer_t *buffer,
+    const axutil_env_t *env
+)
+{
+    AXIS2_ENV_CHECK(env, AXIS2_FAILURE);
+
+    if (buffer->data)
+    {
+        AXIS2_FREE(env->allocator,  buffer->data);
+        buffer->data = NULL;
+    }
+
+    AXIS2_FREE(env->allocator,  buffer);
+    buffer = NULL;
+
+    return AXIS2_SUCCESS;
+}
+
+axis2_status_t AXIS2_CALL
+oxs_buffer_remove_head(
+    oxs_buffer_t *buffer,
+    const axutil_env_t *env,
+    int size
+)
+{
+    AXIS2_ENV_CHECK(env, AXIS2_FAILURE);
+
+    /*If the size to be removed is less than the buffer size*/
+    if (size < buffer->size)
+    {
+        if (!buffer->data)
+        {
+            oxs_error(env, ERROR_LOCATION, OXS_ERROR_INVALID_DATA,
+                      "oxs_buffer_remove_head failed. data is NULL");
+            return  AXIS2_FAILURE;
+        }
+        buffer->size -= size;
+        memmove(buffer->data, buffer->data + size, buffer->size);
+    }
+    else
+    {
+        buffer->size = 0;
+    }
+
+    /*If the buffer size is less than the max_size.*/
+    if (buffer->size < buffer->max_size)
+    {
+        if (!buffer->data)
+        {
+            oxs_error(env, ERROR_LOCATION, OXS_ERROR_INVALID_DATA,
+                      "oxs_buffer_remove_head failed");
+            return  AXIS2_FAILURE;
+        }
+        memset(buffer->data + buffer->size, 0, buffer->max_size - buffer->size);
+    }
+
+    return AXIS2_SUCCESS;
+}
+
+axis2_status_t AXIS2_CALL
+oxs_buffer_remove_tail(
+    oxs_buffer_t *buffer,
+    const axutil_env_t *env,
+    int size
+)
+{
+    AXIS2_ENV_CHECK(env, AXIS2_FAILURE);
+
+    if (size < buffer->size)
+    {
+        buffer->size -= size;
+    }
+    else
+    {
+        buffer->size = 0;
+    }
+    if (buffer->size < buffer->max_size)
+    {
+        if (buffer->data)
+        {
+            oxs_error(env, ERROR_LOCATION, OXS_ERROR_INVALID_DATA,
+                      "");
+            return  AXIS2_FAILURE;
+        }
+        memset(buffer->data + buffer->size, 0, buffer->max_size - buffer->size);
+    }
+
+
+    return AXIS2_SUCCESS;
+}
+
+axis2_status_t AXIS2_CALL
+oxs_buffer_populate(
+    oxs_buffer_t *buffer,
+    const axutil_env_t *env,
+    unsigned char *data,
+    int size
+)
+{
+    AXIS2_ENV_CHECK(env, AXIS2_FAILURE);
+
+    if (size > 0)
+    {
+        oxs_buffer_set_max_size(buffer, env, size);
+        if (!data)
+        {
+            oxs_error(env, ERROR_LOCATION, OXS_ERROR_INVALID_DATA,
+                      "data is NULL");
+            return AXIS2_FAILURE;
+        }
+
+        memcpy(buffer->data, data, size);
+        buffer->size = size;
+    }
+
+    return AXIS2_SUCCESS;
+}
+
+axis2_status_t AXIS2_CALL
+oxs_buffer_append(
+    oxs_buffer_t *buffer,
+    const axutil_env_t *env,
+    unsigned char *data,
+    int size
+)
+{
+    AXIS2_ENV_CHECK(env, AXIS2_FAILURE);
+
+    if (size > 0)
+    {
+        oxs_buffer_set_max_size(buffer, env,  buffer->size + size);
+        if (!data)
+        {
+            oxs_error(env, ERROR_LOCATION, OXS_ERROR_INVALID_DATA,
+                      "data is NULL");
+            return AXIS2_FAILURE;
+        }
+
+        memcpy(buffer->data + buffer->size, data, size);
+        buffer->size += size;
+    }
+
+    return AXIS2_SUCCESS;
+}
+
+axis2_status_t AXIS2_CALL
+oxs_buffer_prepend(
+    oxs_buffer_t *buffer,
+    const axutil_env_t *env,
+    unsigned char *data,
+    int size
+)
+{
+    AXIS2_ENV_CHECK(env, AXIS2_FAILURE);
+
+    if (size > 0)
+    {
+        if (!data)
+        {
+            oxs_error(env, ERROR_LOCATION, OXS_ERROR_INVALID_DATA,
+                      "Passed data is NULL");
+            return AXIS2_FAILURE;
+        }
+
+        buffer->max_size = buffer->size + size;
+
+        memmove(buffer->data + size, buffer->data, buffer->size);
+        memcpy(buffer->data, data, size);
+        buffer->size += size;
+    }
+
+    return AXIS2_SUCCESS;
+}
+
+axis2_status_t AXIS2_CALL
+oxs_buffer_read_file(
+    oxs_buffer_t *buffer,
+    const axutil_env_t *env,
+    const axis2_char_t *filename
+)
+{
+    unsigned char fbuffer[1024];
+    FILE* f;
+    int  len;
+    axis2_status_t status = AXIS2_FAILURE;
+
+    AXIS2_ENV_CHECK(env, AXIS2_FAILURE);
+
+    f = fopen(filename, "rb");
+    if (f == NULL)
+    {
+        oxs_error(env, ERROR_LOCATION, OXS_ERROR_INVALID_DATA,
+                  "");
+        return AXIS2_FAILURE;
+    }
+
+    while (1)
+    {
+        len = fread(fbuffer, 1, sizeof(fbuffer), f);
+        if (len == 0)
+        {
+            break; /*Stop reading*/
+        }
+        else if (len < 0)
+        {
+            fclose(f);
+            return AXIS2_FAILURE;
+        }
+        status = oxs_buffer_append(buffer, env, fbuffer, len);
+        if (status == AXIS2_FAILURE)
+        {
+            fclose(f);
+            oxs_error(env, ERROR_LOCATION, OXS_ERROR_INVALID_DATA,
+                      "");
+            return AXIS2_FAILURE;
+        }
+
+        /*Alright so far everything is fine. So let's close the output*/
+        fclose(f);
+        return AXIS2_SUCCESS;
+    }/*End of while*/
+
+    return AXIS2_SUCCESS;
+}
+
+axis2_status_t AXIS2_CALL
+oxs_buffer_set_size(
+    oxs_buffer_t *buffer,
+    const axutil_env_t *env,
+    int size
+)
+{
+    axis2_status_t status = AXIS2_FAILURE;
+
+    AXIS2_ENV_CHECK(env, AXIS2_FAILURE);
+
+    /*First we need to make sure that the max size has a value greater or equal value*/
+    status = oxs_buffer_set_max_size(buffer, env,  size);
+    if (status == AXIS2_FAILURE)
+    {
+        oxs_error(env, ERROR_LOCATION, OXS_ERROR_INVALID_DATA,
+                  "oxs_buffer_set_max_size failed");
+        return AXIS2_FAILURE;
+    }
+    /*Now set the size*/
+    buffer->size = size;
+
+    return AXIS2_SUCCESS;
+}
+
+axis2_status_t AXIS2_CALL
+oxs_buffer_set_max_size(
+    oxs_buffer_t *buffer,
+    const axutil_env_t *env,
+    int size
+)
+{
+    unsigned char* new_data;
+    unsigned int new_size = 0;
+
+    AXIS2_ENV_CHECK(env, AXIS2_FAILURE);
+
+    if (size <= buffer->max_size)
+    {
+        return AXIS2_SUCCESS;
+    }
+
+    switch (buffer->alloc_mode)
+    {
+    case oxs_alloc_mode_exact:
+        new_size = size + 8;
+        break;
+    case oxs_alloc_mode_double:
+        new_size = 2 * size + 32;
+        break;
+    }
+
+    if (new_size < OXS_BUFFER_INITIAL_SIZE)
+    {
+        new_size = OXS_BUFFER_INITIAL_SIZE;
+    }
+
+    /*If there are data already then use realloc instead of malloc*/
+    if (buffer->data)
+    {
+#if 0
+        new_data = (unsigned char*)AXIS2_REALLOC(env->allocator, buffer_impl->data, new_size);
+#else
+
+        /*Assign extra amnt of memory*/
+        new_data = (unsigned char*)AXIS2_MALLOC(env->allocator, new_size + buffer->max_size);
+
+        /*Copy to newdata*/
+        new_data = memcpy(new_data, buffer->data, buffer->size);
+
+#endif
+    }
+    else
+    {
+        new_data = (unsigned char*)AXIS2_MALLOC(env->allocator, new_size);
+    }
+
+    if (new_data == NULL)
+    {
+        oxs_error(env, ERROR_LOCATION, OXS_ERROR_INVALID_DATA,
+                  "");
+        return AXIS2_FAILURE;
+    }
+
+    buffer->data = new_data;
+    buffer->max_size = new_size;
+
+    if (buffer->size < buffer->max_size)
+    {
+        if (buffer->data == NULL)
+        {
+            oxs_error(env, ERROR_LOCATION, OXS_ERROR_INVALID_DATA,
+                      "");
+            return AXIS2_FAILURE;
+        }
+        memset(buffer->data + buffer->size, 0, buffer->max_size - buffer->size);
+    }
+
+    return AXIS2_SUCCESS;
+}
+
+unsigned char* AXIS2_CALL
+oxs_buffer_get_data(
+    oxs_buffer_t *buffer,
+    const axutil_env_t *env
+)
+{
+    AXIS2_ENV_CHECK(env, NULL);
+
+    return buffer->data;
+}
+
+int AXIS2_CALL
+oxs_buffer_get_size(
+    oxs_buffer_t *buffer,
+    const axutil_env_t *env
+)
+{
+    AXIS2_ENV_CHECK(env, AXIS2_FAILURE);
+
+    return buffer->size;
+}
+
+int AXIS2_CALL
+oxs_buffer_get_max_size(
+    oxs_buffer_t *buffer,
+    const axutil_env_t *env
+)
+{
+    AXIS2_ENV_CHECK(env, AXIS2_FAILURE);
+
+    return buffer->max_size;
+}
+

Added: webservices/rampart/tags/c/0.90/src/omxmlsec/c14n/Makefile.am
URL: http://svn.apache.org/viewvc/webservices/rampart/tags/c/0.90/src/omxmlsec/c14n/Makefile.am?rev=573215&view=auto
==============================================================================
--- webservices/rampart/tags/c/0.90/src/omxmlsec/c14n/Makefile.am (added)
+++ webservices/rampart/tags/c/0.90/src/omxmlsec/c14n/Makefile.am Thu Sep  6 03:48:44 2007
@@ -0,0 +1,11 @@
+lib_LTLIBRARIES = liboxsc14n.la
+
+noinst_HEADERS = c14n_sorted_list.h
+
+liboxsc14n_la_SOURCES = c14n.c \
+					  sorted_list.c
+
+liboxsc14n_la_LIBADD = ${AXIS2C_HOME}/lib
+
+INCLUDES = 	-I ../../../include \
+	    @AXIS2INC@

Added: webservices/rampart/tags/c/0.90/src/omxmlsec/c14n/c14n.c
URL: http://svn.apache.org/viewvc/webservices/rampart/tags/c/0.90/src/omxmlsec/c14n/c14n.c?rev=573215&view=auto
==============================================================================
--- webservices/rampart/tags/c/0.90/src/omxmlsec/c14n/c14n.c (added)
+++ webservices/rampart/tags/c/0.90/src/omxmlsec/c14n/c14n.c Thu Sep  6 03:48:44 2007
@@ -0,0 +1,1680 @@
+
+/*
+ * 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 <stdio.h>
+#include <axis2_const.h>
+#include <axutil_error.h>
+#include <axutil_utils_defines.h>
+#include <axutil_utils.h>
+#include <axutil_env.h>
+#include <axutil_string.h>
+#include <axutil_array_list.h>
+#include <axiom_element.h>
+#include <axiom_children_iterator.h>
+#include <axiom_document.h>
+#include <axiom_comment.h>
+#include <oxs_constants.h>
+#include <oxs_c14n.h>
+#include "c14n_sorted_list.h"
+
+#define N_C14N_DEBUG
+
+#define DEFAULT_STACK_SIZE 16
+#define INIT_BUFFER_SIZE 256
+
+#define c14n_ns_stack_push(save_stack, ctx) \
+        (save_stack)->head = (ctx)->ns_stack->head; \
+        (save_stack)->def_ns = (ctx)->ns_stack->def_ns;
+
+#define c14n_ns_stack_pop(saved_stack, ctx) \
+    (ctx)->ns_stack->head = (saved_stack)->head; \
+    (ctx)->ns_stack->def_ns = (saved_stack)->def_ns;
+
+#define c14n_ns_stack_set_default(ns, ctx) \
+        ((ctx)->ns_stack->def_ns = (ns))
+
+#define c14n_ns_stack_get_default(ctx) \
+        ((ctx)->ns_stack->def_ns)
+
+#define C14N_GET_ROOT_NODE_FROM_DOC_OR_NODE(doc, node, ctx) \
+    ((doc) ? axiom_document_get_root_element((axiom_document_t *)(doc), \
+        (ctx)->env) : c14n_get_root_node((node), (ctx)))
+
+typedef enum {
+    C14N_XML_C14N = 1,
+    C14N_XML_C14N_WITH_COMMENTS,
+    C14N_XML_EXC_C14N,
+    C14N_XML_EXC_C14N_WITH_COMMENTS,
+} c14n_algo_t;
+
+typedef struct c14n_ns_stack {
+    int head; /*index of the currnt stack TOP*/
+    int size; /*total size allocated for current stack*/
+    axiom_namespace_t **stack; /*namespace array*/
+    axiom_namespace_t *def_ns; /*default ns in current scope*/
+} c14n_ns_stack_t;
+
+typedef struct c14n_ctx {
+    const axutil_env_t *env;
+    const axiom_document_t *doc;
+    axis2_bool_t comments;
+    axis2_char_t **outbuf;
+    axutil_stream_t *outstream;
+    axis2_bool_t exclusive;
+    axis2_bool_t use_stream;
+    const axutil_array_list_t *ns_prefixes;
+    const axiom_node_t *node;
+    c14n_ns_stack_t *ns_stack;
+} c14n_ctx_t;
+
+/*Function prototypes for ns stack*/
+
+static c14n_ns_stack_t*
+c14n_ns_stack_create(
+    const c14n_ctx_t *ctx
+);
+
+static void
+c14n_ns_stack_free(
+    c14n_ctx_t *ctx
+);
+
+static axis2_status_t
+c14n_ns_stack_find(
+    const axiom_namespace_t *ns,
+    const c14n_ctx_t *ctx
+);
+
+static axis2_status_t
+c14n_ns_stack_find_with_prefix_uri(
+    const axis2_char_t *prefix,
+    const axis2_char_t *uri,
+    const c14n_ctx_t *ctx
+);
+
+static axis2_status_t
+c14n_ns_stack_add(
+    axiom_namespace_t *ns,
+    const c14n_ctx_t *ctx
+);
+
+/*ns stack implementation*/
+
+static c14n_ns_stack_t*
+c14n_ns_stack_create(
+    const c14n_ctx_t *ctx
+)
+{
+    c14n_ns_stack_t *ns_stack = NULL;
+
+    ns_stack = (c14n_ns_stack_t *)(AXIS2_MALLOC(ctx->env->allocator,
+                                   sizeof(c14n_ns_stack_t)));
+
+    if (ns_stack)
+    {
+        ns_stack->head = 0;
+        ns_stack->size = 0;
+        ns_stack->stack = NULL;
+        ns_stack->def_ns = NULL;
+    }
+    else
+        AXIS2_ERROR_SET(ctx->env->error, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE);
+
+    return ns_stack;
+}
+
+static axis2_status_t
+c14n_ns_stack_add(
+    axiom_namespace_t *ns,
+    const c14n_ctx_t *ctx
+)
+{
+    c14n_ns_stack_t *ns_stack = ctx->ns_stack;
+
+    if (!ns_stack->stack)
+    {
+        ns_stack->stack = (axiom_namespace_t **)(AXIS2_MALLOC(
+                              ctx->env->allocator,
+                              sizeof(axiom_namespace_t*) * DEFAULT_STACK_SIZE));
+        if (!ns_stack->stack)
+        {
+            AXIS2_ERROR_SET(ctx->env->error, AXIS2_ERROR_NO_MEMORY,
+                            AXIS2_FAILURE);
+            return AXIS2_FAILURE;
+        }
+        else ns_stack->size = DEFAULT_STACK_SIZE;
+    }
+    else if (ns_stack->head >= ns_stack->size)
+    {
+        int size = 2 * ns_stack->size;
+        axiom_namespace_t **tmp_stack = (axiom_namespace_t **)(AXIS2_MALLOC(
+                                            ctx->env->allocator, sizeof(axiom_namespace_t*) * size));
+        if (tmp_stack)
+        {
+            /*int i = 0;*/
+            /* TODO:DONE use memcpy for this.*/
+            /*for (i=0; i<ns_stack->size; i++)
+                tmp_stack[i] = (ns_stack->stack)[i];*/
+            memcpy(tmp_stack, ns_stack,
+                   sizeof(axiom_namespace_t*) * ns_stack->size);
+
+            ns_stack->size = size;
+
+            AXIS2_FREE(ctx->env->allocator, ns_stack->stack);
+            ns_stack->stack = tmp_stack;
+        }
+        else
+        {
+            AXIS2_ERROR_SET(ctx->env->error, AXIS2_ERROR_NO_MEMORY,
+                            AXIS2_FAILURE);
+            return AXIS2_FAILURE;
+        }
+    }
+
+    /*if memory overflow occur we won't be here*/
+    (ns_stack->stack)[ns_stack->head] = ns;
+    (ns_stack->head)++;
+
+    return AXIS2_SUCCESS;
+}
+
+/*
+ * TODO: DONE
+ * Find process should be changed ( if the ns has the same prefix but diff uri) 
+ * Eg: <a xmlns:x="a">
+ *      <b xmlns:x="b">
+ *       <c xmlns:x="a"/>
+ *      </b>
+ *     </a>
+ * */
+static axis2_status_t
+c14n_ns_stack_find_with_prefix_uri(
+    const axis2_char_t *prefix,
+    const axis2_char_t *uri,
+    const c14n_ctx_t *ctx
+)
+{
+    int i;
+    c14n_ns_stack_t *ns_stack = ctx->ns_stack;
+    if (ns_stack->stack) /*Is this necessary?*/
+    {
+        for (i = ns_stack->head-1; i>=0; i--)
+        {
+            axis2_char_t *prefix_i = axiom_namespace_get_prefix(
+                                         (ns_stack->stack)[i], ctx->env);
+
+            if (axutil_strcmp(prefix_i, prefix) == 0)
+            {
+                axis2_char_t *uri_i = axiom_namespace_get_uri((ns_stack->stack)[i],
+                                      ctx->env);
+                if (axutil_strcmp(uri_i, uri) == 0)
+                    return AXIS2_SUCCESS;
+                else
+                    return AXIS2_FALSE;
+            }
+            else
+                continue;
+
+        }
+    }
+    return AXIS2_FAILURE;
+}
+
+static axis2_status_t
+c14n_ns_stack_find(
+    const axiom_namespace_t *ns,
+    const c14n_ctx_t *ctx
+)
+{
+    return (c14n_ns_stack_find_with_prefix_uri(
+                axiom_namespace_get_prefix((axiom_namespace_t *)ns, ctx->env),
+                axiom_namespace_get_uri((axiom_namespace_t *)ns, ctx->env), ctx)
+           );
+}
+
+static void
+c14n_ns_stack_free(
+    c14n_ctx_t *ctx
+)
+{
+    if (ctx->ns_stack->stack)
+    {
+        AXIS2_FREE(ctx->env->allocator, ctx->ns_stack->stack);
+        ctx->ns_stack->stack=NULL;
+    }
+    ctx->ns_stack->stack = NULL;
+    ctx->ns_stack->head = 0;
+    ctx->ns_stack->size = 0;
+
+    /**/
+    AXIS2_FREE(ctx->env->allocator, ctx->ns_stack);
+    ctx->ns_stack = NULL;
+}
+
+/* Function Prototypes */
+
+static axis2_status_t
+c14n_apply_on_node(
+    const axiom_node_t *node,
+    const c14n_ctx_t *ctx
+);
+
+static axis2_status_t
+c14n_apply_on_element(
+    const axiom_node_t *node,
+    const c14n_ctx_t *ctx
+);
+
+static axis2_status_t
+c14n_apply_on_namespace_axis(
+    const axiom_element_t *ele,
+    const axiom_node_t *node,
+    const c14n_ctx_t *ctx
+);
+
+static axis2_status_t
+c14n_apply_on_namespace_axis_exclusive(
+    const axiom_element_t *ele,
+    const axiom_node_t *node,
+    const c14n_ctx_t *ctx
+);
+
+static axis2_status_t
+c14n_apply_on_attribute_axis(
+    const axiom_element_t *ele,
+    const c14n_ctx_t *ctx
+);
+
+static axis2_status_t
+c14n_apply_on_node (
+    const axiom_node_t *node,
+    const c14n_ctx_t *ctx
+);
+
+static void
+c14n_apply_on_comment (
+    const axiom_node_t *node,
+    const c14n_ctx_t *ctx
+);
+
+static void
+c14n_output(
+    const axis2_char_t *str,
+    const c14n_ctx_t *ctx
+);
+
+static int
+attr_compare(
+    const void *a1,
+    const void *a2,
+    const void *context
+);
+
+static int
+ns_prefix_compare(
+    const void *ns1,
+    const void *ns2,
+    const void *context
+);
+
+static int
+ns_uri_compare(
+    const void *ns1,
+    const void *ns2,
+    const void *context
+);
+
+static axis2_char_t*
+c14n_normalize_attribute(
+    axis2_char_t *attval,
+    const c14n_ctx_t *ctx
+);
+
+static axis2_char_t*
+c14n_normalize_text(
+    axis2_char_t *text,
+    const c14n_ctx_t *ctx
+);
+
+static void
+c14n_apply_on_namespace(
+    const void *ns,
+    const void *ctx
+);
+
+static axis2_bool_t
+c14n_need_to_declare_ns(
+    const axiom_element_t *ele,
+    const axiom_node_t *node,
+    const axiom_namespace_t *ns,
+    const c14n_ctx_t *ctx
+);
+
+static axis2_bool_t
+c14n_ns_visibly_utilized(
+    const axiom_element_t *ele,
+    const axiom_node_t *node,
+    const axiom_namespace_t *ns,
+    const c14n_ctx_t *ctx
+);
+
+static axis2_bool_t
+c14n_no_output_ancestor_uses_prefix(
+    const axiom_element_t *ele,
+    const axiom_node_t *node,
+    const axiom_namespace_t *ns,
+    const c14n_ctx_t *ctx
+);
+
+static axiom_node_t*
+c14n_get_root_node(
+    const axiom_node_t *node,
+    const c14n_ctx_t *ctx
+);
+
+static c14n_algo_t
+c14n_get_algorithm(
+    const axis2_char_t* algo
+);
+
+/*static axis2_bool_t
+c14n_in_nodeset(
+    const axiom_node_t *node,
+    const c14n_ctx_t *ctx
+    );
+*/
+
+/* Implementations */
+
+static void
+c14n_ctx_free(
+    c14n_ctx_t *ctx
+)
+{
+    if (ctx)
+    {
+        c14n_ns_stack_free(ctx);
+    }
+
+    AXIS2_FREE(ctx->env->allocator, ctx);
+}
+
+static c14n_ctx_t*
+c14n_init(
+    const axutil_env_t *env,
+    const axiom_document_t *doc,
+    axis2_bool_t comments,
+    axis2_char_t **outbuf,
+    axutil_stream_t *stream,
+    const axis2_bool_t exclusive,
+    const axutil_array_list_t *ns_prefixes,
+    const axis2_bool_t use_stream,
+    const axiom_node_t *node
+)
+{
+    c14n_ctx_t *ctx = (c14n_ctx_t *)(AXIS2_MALLOC(env->allocator,
+                                     sizeof(c14n_ctx_t)));
+    if (ctx)
+    {
+        ctx->env = env;
+        ctx->doc = doc;
+        ctx->comments = comments;
+        ctx->outbuf = outbuf;
+        ctx->exclusive = exclusive;
+        ctx->ns_prefixes = ns_prefixes;
+        ctx->use_stream = use_stream;
+        ctx->node = node;
+        if (use_stream)
+            ctx->outstream = stream;
+
+        /*this should come after ctx->env=env*/
+        ctx->ns_stack = c14n_ns_stack_create(ctx);
+    }
+    else
+        AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE);
+
+    return ctx;
+}
+
+/*static axis2_bool_t
+c14n_in_nodeset(
+    const axiom_node_t *node,
+    const c14n_ctx_t *ctx
+    )
+{
+    
+    return AXIS2_SUCCESS;
+}*/
+
+static axiom_node_t*
+c14n_get_root_node(
+    const axiom_node_t *node,
+    const c14n_ctx_t *ctx
+)
+{
+    const axiom_node_t *parent = NULL;
+    const axiom_node_t *prv_parent = NULL;
+
+    parent = node;
+    while (parent)
+    {
+        prv_parent = parent;
+        parent = axiom_node_get_parent((axiom_node_t *)parent, ctx->env);
+    }
+    return (axiom_node_t *)prv_parent;
+}
+
+static c14n_algo_t
+c14n_get_algorithm(
+    const axis2_char_t* algo
+)
+{
+    if (axutil_strcmp(algo, OXS_HREF_XML_C14N) == 0)
+        return C14N_XML_C14N;
+
+    if (axutil_strcmp(algo, OXS_HREF_XML_C14N_WITH_COMMENTS) == 0)
+        return C14N_XML_C14N_WITH_COMMENTS;
+
+    if (axutil_strcmp(algo, OXS_HREF_XML_EXC_C14N) == 0)
+        return C14N_XML_EXC_C14N;
+
+    if (axutil_strcmp(algo, OXS_HREF_XML_EXC_C14N_WITH_COMMENTS) == 0)
+        return C14N_XML_EXC_C14N_WITH_COMMENTS;
+
+    return 0; /*c14n_algo_t enum starts with 1*/
+}
+
+AXIS2_EXTERN axis2_status_t AXIS2_CALL
+oxs_c14n_apply_stream_algo(
+    const axutil_env_t *env,
+    const axiom_document_t *doc,
+    axutil_stream_t *stream,
+    const axutil_array_list_t *ns_prefixes,
+    const axiom_node_t *node,
+    const axis2_char_t* algo
+)
+{
+    switch (c14n_get_algorithm(algo))
+    {
+    case C14N_XML_C14N:
+        return oxs_c14n_apply_stream(env, doc, AXIS2_FALSE, stream, AXIS2_FALSE,
+                                     ns_prefixes, node);
+    case C14N_XML_C14N_WITH_COMMENTS:
+        return oxs_c14n_apply_stream(env, doc, AXIS2_TRUE, stream, AXIS2_FALSE,
+                                     ns_prefixes, node);
+    case C14N_XML_EXC_C14N:
+        return oxs_c14n_apply_stream(env, doc, AXIS2_FALSE, stream, AXIS2_TRUE,
+                                     ns_prefixes, node);
+    case C14N_XML_EXC_C14N_WITH_COMMENTS:
+        return oxs_c14n_apply_stream(env, doc, AXIS2_TRUE, stream, AXIS2_TRUE,
+                                     ns_prefixes, node);
+    default:
+        /*TODO: set the error*/
+        return AXIS2_FAILURE;
+    }
+}
+
+AXIS2_EXTERN axis2_status_t AXIS2_CALL
+oxs_c14n_apply_algo(
+    const axutil_env_t *env,
+    const axiom_document_t *doc,
+    axis2_char_t **outbuf,
+    const axutil_array_list_t *ns_prefixes,
+    const axiom_node_t *node,
+    const axis2_char_t *algo
+)
+{
+    switch (c14n_get_algorithm(algo))
+    {
+    case C14N_XML_C14N:
+        return oxs_c14n_apply(env, doc, AXIS2_FALSE, outbuf, AXIS2_FALSE,
+                              ns_prefixes, node);
+    case C14N_XML_C14N_WITH_COMMENTS:
+        return oxs_c14n_apply(env, doc, AXIS2_TRUE, outbuf, AXIS2_FALSE,
+                              ns_prefixes, node);
+    case C14N_XML_EXC_C14N:
+        return oxs_c14n_apply(env, doc, AXIS2_FALSE, outbuf, AXIS2_TRUE,
+                              ns_prefixes, node);
+    case C14N_XML_EXC_C14N_WITH_COMMENTS:
+        return oxs_c14n_apply(env, doc, AXIS2_TRUE, outbuf, AXIS2_TRUE,
+                              ns_prefixes, node);
+    default:
+        /*TODO:set the error*/
+        return AXIS2_FAILURE;
+    }
+}
+
+AXIS2_EXTERN axis2_status_t AXIS2_CALL
+oxs_c14n_apply_stream(
+    const axutil_env_t *env,
+    const axiom_document_t *doc,
+    axis2_bool_t comments,
+    axutil_stream_t *stream,
+    const axis2_bool_t exclusive,
+    const axutil_array_list_t *ns_prefixes,
+    const axiom_node_t *node
+)
+{
+    c14n_ctx_t *ctx = NULL;
+    axiom_node_t *root_node = NULL;
+    axis2_status_t status = AXIS2_SUCCESS;
+    axiom_element_t *root_ele = NULL;
+    /*axiom_children_iterator_t *child_itr = NULL;*/
+    axutil_stream_t *outstream = NULL;
+
+    ctx = c14n_init(env, doc, comments, NULL, stream, exclusive, ns_prefixes,
+                    AXIS2_TRUE, node);
+
+    if (ctx && ctx->outstream)
+    {
+        root_node = C14N_GET_ROOT_NODE_FROM_DOC_OR_NODE(doc, node, ctx);
+        /*root_node = axiom_document_get_root_element((axiom_document_t *)doc,
+                ctx->env); */
+
+        /* shouldn't the called method's document be const?*/
+
+        root_ele = axiom_node_get_data_element(root_node, env);
+        status = c14n_apply_on_node((node ? node : root_node), ctx);
+
+        if (!status)
+        {
+            axutil_stream_free(ctx->outstream, env);
+            ctx->outstream = NULL;
+        }
+
+        outstream = ctx->outstream;
+
+#ifdef TEST
+        printf("--------------\n");
+        axiom_namespace_t *ns1 = NULL;
+        axiom_namespace_t *ns2 = NULL;
+        axiom_namespace_t *ns3 = NULL;
+        int i = 0;
+        for (i=0; i<17; i++)
+        {
+            char uri[10], pfx[10];
+            sprintf(uri, "urn:ns%d", i);
+            sprintf(pfx, "ns%d", i);
+            ns1 = axiom_namespace_create(ctx->env, uri, pfx);
+            c14n_ns_stack_add(ns1, ctx);
+        }
+        for (i=0; i<ctx->ns_stack->head; i++)
+        {
+            ns1 = ctx->ns_stack->stack[i];
+            printf("%s:%s\n", axiom_namespace_get_prefix(ns1, env),
+                   axiom_namespace_get_uri(ns1, env));
+        }
+        printf("%d\n", ctx->ns_stack->size);
+
+        ns1 = axiom_namespace_create(ctx->env, "urn:ns0", "ns0");
+        ns2 = axiom_namespace_create(ctx->env, "urn:ns10", "ns10");
+        ns3 = axiom_namespace_create(ctx->env, "urn:ns2", "ns3");
+
+        if (c14n_ns_stack_find(ns1, ctx)) printf("ns1 found\n");
+        if (c14n_ns_stack_find(ns2, ctx)) printf("ns2 found\n");
+        if (c14n_ns_stack_find(ns3, ctx)) printf("ns3 found\n");
+#endif
+
+        c14n_ctx_free(ctx);
+        ctx = NULL;
+    }
+    else
+    {
+        AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE);
+
+        if (ctx)
+        {
+            c14n_ctx_free(ctx);
+            ctx = NULL;
+        }
+        status = AXIS2_FAILURE;
+    }
+
+    return status;
+
+    /*if (status)
+        return outstream;
+    else
+        return NULL;*/
+}
+
+
+AXIS2_EXTERN axis2_status_t AXIS2_CALL
+oxs_c14n_apply(
+    const axutil_env_t *env,
+    const axiom_document_t *doc,
+    axis2_bool_t comments,
+    axis2_char_t **outbuf,
+    const axis2_bool_t exclusive,
+    const axutil_array_list_t *ns_prefixes,
+    const axiom_node_t *node
+)
+{
+    axutil_stream_t *stream = axutil_stream_create_basic(env);
+    axis2_status_t ret = oxs_c14n_apply_stream(env, doc, comments,
+                         stream, exclusive, ns_prefixes, node);
+
+    *outbuf = NULL;
+
+    if (!ret)
+    {
+        return AXIS2_FAILURE;
+    }
+    else
+    {
+        int len = axutil_stream_get_len(stream, env)+1;
+        if (len>0)
+        {
+            *outbuf = (axis2_char_t *)(AXIS2_MALLOC(env->allocator,
+                                                    sizeof(axis2_char_t)*len));
+            axutil_stream_read(stream, env, *outbuf, len);
+            axutil_stream_free(stream, env);
+            stream = NULL;
+            return AXIS2_SUCCESS;
+        }
+        else
+        {
+            axutil_stream_free(stream, env);
+            stream = NULL;
+            return AXIS2_FAILURE;
+        }
+    }
+}
+
+static axis2_status_t
+c14n_apply_on_text (
+    const axiom_node_t *node,
+    const c14n_ctx_t *ctx
+)
+{
+    axiom_text_t *text = NULL;
+    text = (axiom_text_t *)axiom_node_get_data_element((axiom_node_t *)node,
+            ctx->env);
+
+    if (text)
+    {
+        axis2_char_t *textval = (axis2_char_t*)axiom_text_get_value(text, ctx->env);
+        textval = c14n_normalize_text(textval, ctx);
+        c14n_output(textval, ctx);
+        if (textval)
+        {
+            AXIS2_FREE(ctx->env->allocator, textval);
+            textval = NULL;
+        }
+    }
+
+    return AXIS2_SUCCESS;
+}
+
+static axis2_status_t
+c14n_apply_on_node (
+    const axiom_node_t *node,
+    const c14n_ctx_t *ctx
+)
+{
+    /*    printf("%d %d %d\n", axiom_node_get_node_type((axiom_node_t *)node, ctx->env), AXIOM_COMMENT, AXIOM_ELEMENT); */
+    switch (axiom_node_get_node_type((axiom_node_t *)node, ctx->env))
+    {
+    case AXIOM_ELEMENT:
+        c14n_apply_on_element(node, ctx);
+        break;
+    case AXIOM_TEXT:
+        c14n_apply_on_text(node, ctx);
+        break;
+    case AXIOM_COMMENT:
+        if (ctx->comments)
+        {
+            c14n_apply_on_comment(node, ctx);
+            break;
+        }
+    case AXIOM_DOCTYPE:
+    case AXIOM_PROCESSING_INSTRUCTION:
+    default:
+        ;
+    }
+
+    return AXIS2_SUCCESS;
+}
+
+static void
+c14n_apply_on_comment (
+    const axiom_node_t *node,
+    const c14n_ctx_t *ctx
+)
+{
+    /*TODO: HACK*/
+    c14n_output("<!--", ctx);
+    c14n_output(axiom_comment_get_value(
+                    (axiom_comment_t*)axiom_node_get_data_element(
+                        (axiom_node_t*)node, ctx->env),ctx->env), ctx);
+    c14n_output("-->", ctx);
+}
+
+static axis2_status_t
+c14n_apply_on_element(
+    const axiom_node_t const *node,
+    const c14n_ctx_t *ctx
+)
+{
+    axis2_status_t res = AXIS2_SUCCESS;
+    axiom_element_t *ele = NULL;
+    axiom_namespace_t *ns = NULL;
+    /*axiom_children_iterator_t *child_itr = NULL;*/
+    c14n_ns_stack_t *save_stack = NULL;
+    axiom_node_t *child_node = NULL;
+
+    ele = (axiom_element_t *)axiom_node_get_data_element((axiom_node_t *)node,
+            ctx->env);
+
+    if (!ele) return AXIS2_FAILURE; /*should it be failure?*/
+
+    ns = axiom_element_get_namespace(ele, ctx->env, (axiom_node_t *)node);
+
+    save_stack = c14n_ns_stack_create(ctx);
+    c14n_ns_stack_push(save_stack, ctx); /*save current ns stack*/
+
+    /*print qname*/
+    c14n_output("<", ctx);
+
+    if (ns)
+    {
+        axis2_char_t *prefix = axiom_namespace_get_prefix(ns, ctx->env);
+
+        if (axutil_strlen(prefix) > 0)
+        {
+            c14n_output(prefix, ctx);
+            c14n_output(":", ctx);
+        }
+    }
+    c14n_output(axiom_element_get_localname(ele, ctx->env), ctx);
+
+    if (ctx->exclusive)
+        res = c14n_apply_on_namespace_axis_exclusive(ele, node, ctx);
+    else
+        res = c14n_apply_on_namespace_axis(ele, node, ctx);
+
+    /*
+     * edited the code so that the same fn does both exc and non-exc.
+     * have to be careful here!
+     */
+
+    if (!res) return res;
+
+    res = c14n_apply_on_attribute_axis(ele, ctx);
+
+    if (!res) return res;
+
+    c14n_output(">", ctx);
+
+#ifdef C14N_DEBUG
+    /*c14n_output("\n", ctx);*/
+#endif
+
+    /*process child elements*/
+
+    child_node = axiom_node_get_first_child((axiom_node_t *)node, ctx->env);
+
+    while (child_node)
+    {
+        c14n_apply_on_node(child_node, ctx);
+        child_node = axiom_node_get_next_sibling(child_node, ctx->env);
+    }
+
+    /*process child elements*/
+
+    /*child_itr = AXIOM_ELEMENT_GET_CHILDREN(ele, ctx->env, (axiom_node_t*)node);
+    if (child_itr)
+    {
+
+        while(axiom_children_iterator_has_next(child_itr, ctx->env))
+        {
+            axiom_node_t *child_node = NULL;
+            child_node = axiom_children_iterator_next(child_itr, ctx->env);
+            
+            if (child_node)
+            {
+                c14n_apply_on_node(child_node, ctx);
+            }
+        }
+    }*/
+
+
+    /*print qname*/
+    c14n_output("</", ctx);
+
+    if (ns)
+    {
+        axis2_char_t *prefix = axiom_namespace_get_prefix(ns, ctx->env);
+
+        if (axutil_strlen(prefix) > 0)
+        {
+            c14n_output(prefix, ctx);
+            c14n_output(":", ctx);
+        }
+    }
+    c14n_output(axiom_element_get_localname(ele, ctx->env), ctx);
+
+    c14n_output(">", ctx);
+
+    c14n_ns_stack_pop(save_stack, ctx); /*restore to previous ns stack */
+    /*TODO:DONE??? save_stack free*/
+    /*since save_stack is used just to memorize the head of the stack,
+     * we don't have to worry about freeing its members*/
+
+    /**/
+    AXIS2_FREE(ctx->env->allocator, save_stack);
+    save_stack = NULL;
+
+#ifdef C14N_DEBUG
+    /*c14n_output("\n", ctx);*/
+#endif
+
+    return res;
+}
+
+static int
+ns_uri_compare(
+    const void *ns1,
+    const void *ns2,
+    const void *context
+)
+{
+    c14n_ctx_t *ctx = (c14n_ctx_t *)context;
+
+    if (ns1 == ns2) return 0;
+    if (!ns1) return -1;
+    if (!ns2) return 1;
+
+    return (axutil_strcmp(
+                (const axis2_char_t *)axiom_namespace_get_uri(
+                    (axiom_namespace_t *)ns1, ctx->env),
+                (const axis2_char_t *)axiom_namespace_get_uri(
+                    (axiom_namespace_t *)ns2, ctx->env)));
+}
+
+static int
+ns_prefix_compare(
+    const void *ns1,
+    const void *ns2,
+    const void *context
+)
+{
+    c14n_ctx_t *ctx = (c14n_ctx_t *)context;
+
+    if (ns1 == ns2) return 0;
+    if (!ns1) return -1;
+    if (!ns2) return 1;
+
+    return (axutil_strcmp(
+                (const axis2_char_t *)axiom_namespace_get_prefix(
+                    (axiom_namespace_t *)ns1, ctx->env),
+                (const axis2_char_t *)axiom_namespace_get_prefix(
+                    (axiom_namespace_t *)ns2, ctx->env)));
+}
+
+static int
+attr_compare(
+    const void *a1,
+    const void *a2,
+    const void *context
+)
+{
+    c14n_ctx_t *ctx = (c14n_ctx_t *)context;
+    axiom_attribute_t *attr1 = NULL;
+    axiom_attribute_t *attr2 = NULL;
+    axiom_namespace_t *ns1 = NULL;
+    axiom_namespace_t *ns2 = NULL;
+    int res;
+
+    if (a1 == a2) return 0;
+    if (!a1) return -1;
+    if (!a2) return 1;
+
+    attr1 = (axiom_attribute_t *)a1;
+    attr2 = (axiom_attribute_t *)a2;
+    ns1 = axiom_attribute_get_namespace((axiom_attribute_t *)a1, ctx->env);
+    ns2 = axiom_attribute_get_namespace((axiom_attribute_t *)a2, ctx->env);
+
+    if (ns1 == ns2)
+        return axutil_strcmp(
+                   (const axis2_char_t *)axiom_attribute_get_localname(
+                       (axiom_attribute_t *)a1, ctx->env),
+                   (const axis2_char_t *)axiom_attribute_get_localname(
+                       (axiom_attribute_t *)a2, ctx->env));
+
+    if (!ns1) return -1;
+    if (!ns2) return 1;
+
+    res = axutil_strcmp(
+              axiom_namespace_get_uri(ns1, ctx->env),
+              axiom_namespace_get_uri(ns2, ctx->env));
+
+    if (res == 0)
+        return axutil_strcmp(
+                   (const axis2_char_t *)axiom_attribute_get_localname(
+                       (axiom_attribute_t *)a1, ctx->env),
+                   (const axis2_char_t *)axiom_attribute_get_localname(
+                       (axiom_attribute_t *)a2, ctx->env));
+    else
+        return res;
+
+}
+
+
+
+static void
+c14n_apply_on_attribute(
+    const void *attribute,
+    const void *context
+)
+{
+    c14n_ctx_t *ctx = (c14n_ctx_t *) context;
+    axiom_attribute_t *attr = (axiom_attribute_t *) attribute;
+    axiom_namespace_t *ns = axiom_attribute_get_namespace(attr, ctx->env);
+    axis2_char_t *attvalue = NULL;
+
+    c14n_output(" ", ctx);
+    if (ns)
+    {
+        axis2_char_t *prefix = axiom_namespace_get_prefix(ns, ctx->env);
+
+        if (axutil_strlen(prefix) > 0)
+        {
+            c14n_output(prefix, ctx);
+            c14n_output(":", ctx);
+        }
+    }
+    c14n_output(axiom_attribute_get_localname(attr, ctx->env), ctx);
+    c14n_output("=\"", ctx);
+
+    /* TODO:DONE Normalize the text before output */
+    attvalue = axiom_attribute_get_value(attr, ctx->env);
+    attvalue = c14n_normalize_attribute(attvalue, (c14n_ctx_t const *)context);
+
+    c14n_output(attvalue, ctx);
+
+    c14n_output("\"", ctx);
+
+    if (attvalue)
+    {
+        AXIS2_FREE(ctx->env->allocator, attvalue);
+        attvalue = NULL;
+    }
+}
+
+static axis2_status_t
+c14n_apply_on_attribute_axis(
+    const axiom_element_t *ele,
+    const c14n_ctx_t *ctx
+)
+{
+    axutil_hash_t *attr_ht = NULL;
+    axutil_hash_index_t *hi = NULL;
+    c14n_sorted_list_t *attr_list = c14n_sorted_list_create(ctx->env);
+
+    attr_ht = axiom_element_get_all_attributes((axiom_element_t *)ele,
+              ctx->env);
+
+    if(attr_ht)
+    {
+        for (hi = axutil_hash_first(attr_ht, ctx->env); hi;
+                hi = axutil_hash_next(ctx->env, hi))
+        {
+            void *v = NULL;
+            axutil_hash_this(hi, NULL, NULL, &v);
+
+            if (v)
+            {
+                C14N_SORTED_LIST_INSERT(&attr_list, v, ctx, attr_compare,
+                                        ctx->env);
+            }
+        }
+
+        C14N_SORTED_LIST_ITERATE(attr_list, ctx, c14n_apply_on_attribute,
+                                 ctx->env);
+    }
+
+    /*TODO:DONE C14N_SORTED_LIST_FREE();*/
+    C14N_SORTED_LIST_FREE_CONTAINER(attr_list, ctx->env);
+
+    return AXIS2_SUCCESS;
+
+    /* TODO: Still need to add the "xml" attrs of the parents in case of doc subsets
+     * and non-exclusive c14n
+     * */
+}
+
+static axis2_char_t*
+c14n_normalize_text(
+    axis2_char_t *text,
+    const c14n_ctx_t *ctx
+)
+{
+    axis2_char_t *buf = NULL;
+    axis2_char_t *endpivot = NULL;
+    axis2_char_t *p = NULL;
+    axis2_char_t *old = NULL;
+    int bufsz = INIT_BUFFER_SIZE;
+
+    /* TODO:DONE a better buffer implementation */
+    buf = (axis2_char_t *)(AXIS2_MALLOC(ctx->env->allocator,
+                                        (sizeof(axis2_char_t) * bufsz) + 10));
+    if (!buf)
+    {
+        AXIS2_ERROR_SET(ctx->env->error, AXIS2_ERROR_NO_MEMORY,
+                        AXIS2_FAILURE);
+        return buf;
+    }
+
+    p = buf;
+    endpivot = p + bufsz;
+
+    old = text;
+
+    while (*old !='\0')
+    {
+        if (p > endpivot)
+        {
+            int size = bufsz * 2;
+            axis2_char_t *temp_buf = (axis2_char_t *)(AXIS2_MALLOC(
+                                         ctx->env->allocator, sizeof(axis2_char_t) * size + 10));
+
+            if (!temp_buf)
+            {
+                AXIS2_ERROR_SET(ctx->env->error, AXIS2_ERROR_NO_MEMORY,
+                                AXIS2_FAILURE);
+                return buf;
+            }
+
+            memcpy(temp_buf, buf, sizeof(axis2_char_t) * bufsz + 10);
+
+            p = temp_buf + (p - buf);
+
+            AXIS2_FREE(ctx->env->allocator, buf);
+            buf = temp_buf;
+            bufsz = size;
+            endpivot = buf + bufsz;
+        }
+
+        switch (*old)
+        {
+        case '&':
+            *p++ = '&';
+            *p++ = 'a';
+            *p++ = 'm';
+            *p++ = 'p';
+            *p++ = ';';
+            break;
+        case '>':
+            *p++ = '&';
+            *p++ = 'g';
+            *p++ = 't';
+            *p++ = ';';
+            break;
+        case '<':
+            *p++ = '&';
+            *p++ = 'l';
+            *p++ = 't';
+            *p++ = ';';
+            break;
+        case '\x0D':
+            *p++ = '&';
+            *p++ = '#';
+            *p++ = 'x';
+            *p++ = 'D';
+            *p++ = ';';
+            break;
+        default:
+            *p++ = *old;
+        }
+        old ++;
+    }
+    *p++ = '\0';
+    return buf;
+}
+
+static axis2_char_t*
+c14n_normalize_attribute(
+    axis2_char_t *attval,
+    const c14n_ctx_t *ctx
+)
+{
+    axis2_char_t *buf = NULL;
+    axis2_char_t *endpivot = NULL;
+    axis2_char_t *p = NULL;
+    axis2_char_t *old = NULL;
+    int bufsz = INIT_BUFFER_SIZE;
+
+    /* TODO:DONE a better buffer implementation */
+    buf = (axis2_char_t *)(AXIS2_MALLOC(ctx->env->allocator,
+                                        sizeof(axis2_char_t) * INIT_BUFFER_SIZE + 10));
+    if (!buf)
+    {
+        AXIS2_ERROR_SET(ctx->env->error, AXIS2_ERROR_NO_MEMORY,
+                        AXIS2_FAILURE);
+        return buf;
+    }
+
+    p = buf;
+    endpivot = buf + bufsz;
+
+    old = attval;
+
+    while (*old !='\0')
+    {
+        if (p > endpivot)
+        {
+            int size = bufsz * 2;
+            axis2_char_t *temp_buf = (axis2_char_t *)(AXIS2_MALLOC(
+                                         ctx->env->allocator, sizeof(axis2_char_t) * size + 10));
+
+            if (!temp_buf)
+            {
+                AXIS2_ERROR_SET(ctx->env->error, AXIS2_ERROR_NO_MEMORY,
+                                AXIS2_FAILURE);
+                return buf;
+            }
+
+            memcpy(temp_buf, buf, sizeof(axis2_char_t) * bufsz + 10);
+
+            p = temp_buf + (p - buf);
+
+            AXIS2_FREE(ctx->env->allocator, buf);
+            buf = temp_buf;
+            bufsz = size;
+            endpivot = buf + bufsz;
+        }
+
+        switch (*old)
+        {
+        case '&':
+            *p++ = '&';
+            *p++ = 'a';
+            *p++ = 'm';
+            *p++ = 'p';
+            *p++ = ';';
+            break;
+        case '<':
+            *p++ = '&';
+            *p++ = 'l';
+            *p++ = 't';
+            *p++ = ';';
+            break;
+        case '"':
+            *p++ = '&';
+            *p++ = 'q';
+            *p++ = 'u';
+            *p++ = 'o';
+            *p++ = 't';
+            *p++ = ';';
+            break;
+        case '\x09':
+            *p++ = '&';
+            *p++ = '#';
+            *p++ = 'x';
+            *p++ = '9';
+            *p++ = ';';
+            break;
+        case '\x0A':
+            *p++ = '&';
+            *p++ = '#';
+            *p++ = 'x';
+            *p++ = 'A';
+            *p++ = ';';
+            break;
+        case '\x0D':
+            *p++ = '&';
+            *p++ = '#';
+            *p++ = 'x';
+            *p++ = 'D';
+            *p++ = ';';
+            break;
+        default:
+            *p++ = *old;
+        }
+        old ++;
+    }
+    *p++ = '\0';
+    return buf;
+}
+
+
+static axis2_status_t
+c14n_apply_on_namespace_axis(
+    const axiom_element_t *ele,
+    const axiom_node_t *node,
+    const c14n_ctx_t *ctx
+)
+{
+    axutil_hash_t *ns_ht = NULL;
+    axutil_hash_index_t *hi = NULL;
+
+    c14n_sorted_list_t *out_list = c14n_sorted_list_create(ctx->env);
+
+
+    ns_ht = axiom_element_get_namespaces((axiom_element_t *)ele, ctx->env);
+
+    if(ns_ht)
+    {
+        for (hi = axutil_hash_first(ns_ht, ctx->env); hi;
+                hi = axutil_hash_next(ctx->env, hi))
+        {
+            void *v = NULL;
+            axutil_hash_this(hi, NULL, NULL, &v);
+
+            if (v)
+            {
+                axiom_namespace_t *ns = (axiom_namespace_t *) v;
+
+                axis2_char_t *pfx = axiom_namespace_get_prefix(ns, ctx->env);
+                axis2_char_t *uri = axiom_namespace_get_uri(ns, ctx->env);
+
+                if (axutil_strlen(pfx) == 0)
+                {
+                    /*process for default namespace*/
+                    /*int nsc = ns_prefix_compare(c14n_ns_stack_get_default(ctx), ns, ctx);
+                    int len = axutil_strlen(uri);*/
+
+                    if (axutil_strlen(uri) == 0)
+                    {
+                        if (c14n_ns_stack_get_default(ctx)!=NULL)
+                        {
+                            c14n_ns_stack_set_default(ns, ctx);
+                            C14N_SORTED_LIST_INSERT(&out_list, (void *)ns, ctx,
+                                                    ns_prefix_compare, ctx->env);
+                        }
+
+                    }
+                    else
+                    {
+                        axiom_namespace_t *prev_def =
+                            c14n_ns_stack_get_default(ctx);
+
+                        axis2_char_t *prev_def_uri = ((prev_def) ?
+                                                      axiom_namespace_get_uri(prev_def, ctx->env) : NULL);
+
+
+                        if (!prev_def_uri || axutil_strcmp(prev_def_uri, uri) != 0)
+                        {
+                            c14n_ns_stack_set_default(ns, ctx);
+                            C14N_SORTED_LIST_INSERT(&out_list, (void *)ns, ctx,
+                                                    ns_prefix_compare, ctx->env);
+                        }
+                    }
+                }
+                else if (!c14n_ns_stack_find(ns, ctx))
+                {
+                    /*non-default namespace*/
+                    c14n_ns_stack_add(ns, ctx);
+                    C14N_SORTED_LIST_INSERT(&out_list, (void *)ns, ctx,
+                                            ns_prefix_compare, ctx->env);
+                }
+            }
+        }
+    }
+
+    C14N_SORTED_LIST_ITERATE(out_list, ctx, c14n_apply_on_namespace, ctx->env);
+
+    C14N_SORTED_LIST_FREE_CONTAINER(out_list, ctx->env);
+
+    /*TODO:DONE C14N_SORTED_LIST_FREE();*/
+    return AXIS2_SUCCESS;
+}
+
+static axis2_status_t
+c14n_apply_on_namespace_axis_exclusive(
+    const axiom_element_t *ele,
+    const axiom_node_t *node,
+    const c14n_ctx_t *ctx
+)
+{
+    axutil_hash_t *ns_ht = NULL;
+    axutil_hash_index_t *hi = NULL;
+    axiom_node_t *pnode = NULL;
+    axiom_element_t *pele = NULL;
+    axiom_namespace_t *ns = NULL;
+
+    c14n_sorted_list_t *out_list = c14n_sorted_list_create(ctx->env);
+
+    pele = (axiom_element_t *)ele;
+    pnode = (axiom_node_t *)node;
+
+    /*treat the default namespace specially*/
+
+    ns = axiom_element_get_namespace(pele, ctx->env,
+                                     pnode);
+
+    if (ns)
+    {
+        if (axutil_strlen(axiom_namespace_get_prefix((axiom_namespace_t *)ns,
+                         ctx->env)) == 0)
+        {
+            axiom_namespace_t *def_ns = c14n_ns_stack_get_default(ctx);
+            if (def_ns || axutil_strlen(axiom_namespace_get_uri(
+                                           (axiom_namespace_t *)ns, ctx->env)) != 0)
+            {
+                if (ns_uri_compare(ns, def_ns, ctx) != 0)
+                {
+                    c14n_ns_stack_set_default(ns, ctx);
+                    C14N_SORTED_LIST_INSERT(&out_list, (void *)ns,
+                                            ctx, ns_prefix_compare, ctx->env);
+                }
+            }
+        }
+    }
+
+    while (pnode)
+    {
+        pele = axiom_node_get_data_element((axiom_node_t *)pnode, ctx->env);
+        ns_ht = axiom_element_get_namespaces((axiom_element_t *)pele, ctx->env);
+
+        if (ns_ht)
+        {
+            for (hi = axutil_hash_first(ns_ht, ctx->env); hi;
+                    hi = axutil_hash_next(ctx->env, hi))
+            {
+                void *v = NULL;
+                axutil_hash_this(hi, NULL, NULL, &v);
+
+                if (v)
+                {
+                    axis2_char_t *pfx = NULL;
+                    ns = (axiom_namespace_t *) v;
+
+                    pfx = axiom_namespace_get_prefix(ns, ctx->env);
+                    /*axis2_char_t *uri = axiom_namespace_get_uri(ns, ctx->env);*/
+
+                    if (axutil_strlen(pfx) == 0)
+                    {
+                        /* process for default namespace.
+                         * NOTE: This part was taken out of here due to the 
+                         * search thruogh parent-axis
+                         * */
+                    }
+                    else if (!c14n_ns_stack_find(ns, ctx))
+                    {
+                        /*non-default namespace*/
+                        if (c14n_need_to_declare_ns(ele, node, ns, ctx))
+                        {
+                            c14n_ns_stack_add(ns, ctx);
+                            C14N_SORTED_LIST_INSERT(&out_list, (void *)ns, ctx,
+                                                    ns_prefix_compare, ctx->env);
+                        }
+                    }
+                }
+            }
+        }
+        pnode = axiom_node_get_parent((axiom_node_t *)pnode, ctx->env);
+    } /*while*/
+    C14N_SORTED_LIST_ITERATE(out_list, ctx, c14n_apply_on_namespace , ctx->env);
+
+    C14N_SORTED_LIST_FREE_CONTAINER(out_list, ctx->env);
+
+    /*TODO:DONE C14N_SORTED_LIST_FREE();*/
+    return AXIS2_SUCCESS;
+}
+
+static void
+c14n_apply_on_namespace(
+    const void *namespace,
+    const void *context
+)
+{
+    axiom_namespace_t *ns = (axiom_namespace_t *)namespace;
+    c14n_ctx_t *ctx = (c14n_ctx_t *)context;
+
+    axis2_char_t *pfx = axiom_namespace_get_prefix(ns, ctx->env);
+    axis2_char_t *uri = axiom_namespace_get_uri(ns, ctx->env);
+
+    /*c14n_output(" *", ctx);
+    c14n_output(axiom_namespace_to_string(ns, ctx->env), ctx);
+    c14n_output("*", ctx);*/
+
+    if (axutil_strlen(pfx) > 0)
+    {
+        c14n_output(" xmlns:", ctx);
+        c14n_output(pfx, ctx);
+    }
+    else
+        c14n_output(" xmlns", ctx);
+
+    c14n_output("=\"", ctx);
+
+    if (axutil_strlen(uri) > 0)
+        c14n_output(uri, ctx);
+    c14n_output("\"", ctx);
+
+}
+
+static void
+c14n_output(
+    const axis2_char_t *str,
+    const c14n_ctx_t *ctx
+)
+{
+#ifdef C14N_DEBUG
+    printf("%s", str);
+#else
+    if (ctx->use_stream)
+    {
+        axutil_stream_write(ctx->outstream, ctx->env, str,
+                           axutil_strlen(str)*sizeof(axis2_char_t));
+    }
+#endif
+}
+
+static axis2_bool_t
+c14n_need_to_declare_ns(
+    const axiom_element_t *ele,
+    const axiom_node_t *node,
+    const axiom_namespace_t *ns,
+    const c14n_ctx_t *ctx
+)
+{
+    axis2_bool_t vu = c14n_ns_visibly_utilized(ele, node, ns, ctx);
+
+    if (vu || (ctx->ns_prefixes && axutil_array_list_contains(
+                   (axutil_array_list_t*)(ctx->ns_prefixes), ctx->env,
+                   (void*)(axiom_namespace_get_prefix((axiom_namespace_t*)ns,
+                                                      ctx->env)))))
+        return c14n_no_output_ancestor_uses_prefix(ele, node, ns, ctx);
+
+    return AXIS2_FALSE;
+}
+
+static axis2_bool_t
+c14n_ns_visibly_utilized(
+    const axiom_element_t *ele,
+    const axiom_node_t *node,
+    const axiom_namespace_t *ns,
+    const c14n_ctx_t *ctx
+)
+{
+    axis2_bool_t vu = AXIS2_FALSE;
+    axiom_namespace_t *ns_ele = NULL;
+
+    axis2_char_t *pfx = axiom_namespace_get_prefix((axiom_namespace_t*)ns,
+                        ctx->env);
+    axis2_char_t *uri = axiom_namespace_get_uri((axiom_namespace_t *)ns,
+                        ctx->env);
+    axis2_char_t *pfx_ele = NULL;
+    axis2_char_t *uri_ele = NULL;
+    ns_ele = axiom_element_get_namespace((axiom_element_t*)ele, ctx->env,
+                                         (axiom_node_t *)node);
+
+    if (ns_ele)  /* return AXIS2_FALSE; TODO:check */
+    {
+        pfx_ele = axiom_namespace_get_prefix(ns_ele, ctx->env);
+        uri_ele = axiom_namespace_get_uri(ns_ele, ctx->env);
+    }
+    if ((axutil_strcmp(pfx, pfx_ele) == 0) && (axutil_strcmp(uri, uri_ele) == 0))
+        vu = AXIS2_TRUE;
+    else
+    {
+        axutil_hash_t *attr_ht = axiom_element_get_all_attributes(
+                                    (axiom_element_t *)ele, ctx->env);
+        axutil_hash_index_t *hi = NULL;
+        if (attr_ht)
+        {
+            for (hi = axutil_hash_first(attr_ht, ctx->env); hi;
+                    hi = axutil_hash_next(ctx->env, hi))
+            {
+                void *v = NULL;
+                axutil_hash_this(hi, NULL, NULL, &v);
+
+                if (v)
+                {
+                    axiom_attribute_t *attr = (axiom_attribute_t*)v;
+                    axiom_namespace_t *ns_attr = axiom_attribute_get_namespace(
+                                                     attr, ctx->env);
+                    axis2_char_t *attr_pfx = NULL;
+
+                    /*if in_nodelist(attr) {*/
+                    if (ns_attr)
+                        attr_pfx = axiom_namespace_get_prefix(
+                                       ns_attr, ctx->env);
+
+                    if (axutil_strcmp(attr_pfx, pfx) == 0)
+                    {
+                        vu = AXIS2_TRUE;
+                        break;
+                    }
+                    /*}*/
+                }
+            }
+        }
+
+    }
+
+    return vu;
+}
+
+static axis2_bool_t
+in_nodeset(
+    const axiom_node_t *node,
+    const c14n_ctx_t *ctx
+)
+{
+    axiom_node_t *pnode = NULL;
+    pnode = axiom_node_get_parent((axiom_node_t *)node, ctx->env);
+
+    while (pnode)
+    {
+        if (ctx->node == pnode) return AXIS2_TRUE;
+        pnode = axiom_node_get_parent((axiom_node_t *)pnode, ctx->env);
+    }
+
+    return AXIS2_FALSE;
+}
+
+static axis2_bool_t
+c14n_no_output_ancestor_uses_prefix(
+    const axiom_element_t *ele,
+    const axiom_node_t *node,
+    const axiom_namespace_t *ns,
+    const c14n_ctx_t *ctx
+)
+{
+    axis2_char_t *pfx = axiom_namespace_get_prefix((axiom_namespace_t*)ns,
+                        ctx->env);
+    axis2_char_t *uri = axiom_namespace_get_uri((axiom_namespace_t *)ns,
+                        ctx->env);
+
+    axiom_node_t *parent_node = axiom_node_get_parent((axiom_node_t *)node,
+                                ctx->env);
+    axiom_element_t *parent_element = NULL;
+    axiom_namespace_t *parent_ns = NULL;
+    axis2_char_t *parent_pfx = NULL;
+    axis2_char_t *parent_uri = NULL;
+
+    /* assuming the parent  of an element is always an element node in AXIOM*/
+    while (parent_node)
+    {
+        axutil_hash_index_t *hi = NULL;
+        axutil_hash_t *attr_ht = NULL;
+
+        /* TODO:
+         * HACK: since we only use a single node as the subset
+         * the following hack should work instead of a more
+         * general in_nodest()*/
+
+        if (!in_nodeset(node, ctx))
+        {
+            /*we reached a node beyond the nodeset,
+             * so the prefix is not used*/
+            return AXIS2_TRUE;
+        }
+
+        /* if (in_nodeset(parent)){*/
+        parent_element = axiom_node_get_data_element(
+                             (axiom_node_t *)parent_node, ctx->env);
+        parent_ns = axiom_element_get_namespace((axiom_element_t *)
+                                                parent_element, ctx->env, (axiom_node_t *)parent_node);
+
+        if (parent_ns)
+        {
+            parent_pfx = axiom_namespace_get_prefix((axiom_namespace_t *)parent_ns,
+                                                    ctx->env);
+            if (axutil_strcmp(pfx, parent_pfx) == 0)
+            {
+                parent_uri = axiom_namespace_get_uri((axiom_namespace_t*)parent_ns,
+                                                     ctx->env);
+                return (!(axutil_strcmp(uri, parent_uri) == 0));
+            }
+        }
+
+        attr_ht = axiom_element_get_all_attributes(
+                      (axiom_element_t *)parent_element, ctx->env);
+        if (attr_ht)
+        {
+            for (hi = axutil_hash_first(attr_ht, ctx->env); hi;
+                    hi = axutil_hash_next(ctx->env, hi))
+            {
+                void *v = NULL;
+                axutil_hash_this(hi, NULL, NULL, &v);
+
+                if (v)
+                {
+                    axiom_attribute_t *attr = (axiom_attribute_t*)v;
+                    axiom_namespace_t *attr_ns = axiom_attribute_get_namespace(
+                                                     attr, ctx->env);
+                    axis2_char_t *attr_pfx = NULL;
+                    axis2_char_t *attr_uri = NULL;
+
+                    if (attr_ns)
+                    {
+                        attr_pfx = axiom_namespace_get_prefix(
+                                       attr_ns, ctx->env);
+                        attr_uri = axiom_namespace_get_uri(attr_ns,
+                                                           ctx->env);
+
+                        if (axutil_strcmp(attr_pfx, pfx) == 0)
+                            return (!(axutil_strcmp(attr_uri, uri) == 0));
+                        /*test for this case*/
+                    }
+                }
+            }
+        }
+        /*}*/
+        parent_node = axiom_node_get_parent((axiom_node_t *)parent_node,
+                                            ctx->env);
+    }
+
+    return AXIS2_TRUE;
+}

Added: webservices/rampart/tags/c/0.90/src/omxmlsec/c14n/c14n_sorted_list.h
URL: http://svn.apache.org/viewvc/webservices/rampart/tags/c/0.90/src/omxmlsec/c14n/c14n_sorted_list.h?rev=573215&view=auto
==============================================================================
--- webservices/rampart/tags/c/0.90/src/omxmlsec/c14n/c14n_sorted_list.h (added)
+++ webservices/rampart/tags/c/0.90/src/omxmlsec/c14n/c14n_sorted_list.h Thu Sep  6 03:48:44 2007
@@ -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 C14N_SORTED_LIST_H
+#define C14N_SORTED_LIST_H
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+    typedef struct c14n_sorted_list c14n_sorted_list_t;
+
+
+    struct c14n_sorted_list {
+        void *val;
+        c14n_sorted_list_t *right, *left;
+    };
+
+    void
+    sorted_list_insert(
+        c14n_sorted_list_t **node,
+        void *val,
+        const void *ctx,
+        int(*compar)(const void *, const void *, const void *)
+        );
+
+
+    void
+    sorted_list_iterate(
+        c14n_sorted_list_t *root,
+        const void *ctx,
+        void(*perform)(const void *, const void *),
+        const axutil_env_t *env
+        );
+
+    void
+    sorted_list_free_container(
+        c14n_sorted_list_t *root,
+        const axutil_env_t *env
+        );
+
+#ifdef __cplusplus
+}
+#endif
+
+#define C14N_SORTED_LIST_INSERT(list, val, ctx, compar, env)\
+    sorted_list_insert(list, val, ctx, compar)
+
+#define c14n_sorted_list_create(env) NULL
+
+#define C14N_SORTED_LIST_FREE(list, fp_free, env) sorted_list_free(list, fp_free)
+
+#define C14N_SORTED_LIST_ITERATE(list, ctx, fp_perform, env)\
+    sorted_list_iterate(list, ctx, fp_perform, env)
+
+#define C14N_SORTED_LIST_FREE_CONTAINER(list, env)\
+    sorted_list_free_container(list, env);\
+    AXIS2_FREE(env->allocator, list)
+
+#endif

Added: webservices/rampart/tags/c/0.90/src/omxmlsec/c14n/sorted_list.c
URL: http://svn.apache.org/viewvc/webservices/rampart/tags/c/0.90/src/omxmlsec/c14n/sorted_list.c?rev=573215&view=auto
==============================================================================
--- webservices/rampart/tags/c/0.90/src/omxmlsec/c14n/sorted_list.c (added)
+++ webservices/rampart/tags/c/0.90/src/omxmlsec/c14n/sorted_list.c Thu Sep  6 03:48:44 2007
@@ -0,0 +1,139 @@
+
+/*
+ * 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 <stdlib.h>
+#include <stdio.h>
+#include <axutil_env.h>
+#include "c14n_sorted_list.h"
+
+/*
+ * Quick and dirty hack for a sorted list. This must later be
+ * reimplemented
+ * */
+
+void
+sorted_list_iterate(
+    c14n_sorted_list_t *root,
+    const void *ctx,
+    void(*perform)(const void *, const void *),
+    const axutil_env_t *env
+)
+{
+    if (!root) return;
+    if(root->left) sorted_list_iterate(root->left, ctx, perform, env);
+    perform(root->val, ctx);
+    if(root->right) sorted_list_iterate(root->right, ctx, perform, env);
+}
+
+void
+sorted_list_insert(
+    c14n_sorted_list_t **node,
+    void *val,
+    const void *ctx,
+    int(*compar)(const void *, const void *, const void *)
+)
+{
+    if(!(*node)) {
+        *node = (c14n_sorted_list_t *) malloc(sizeof(**node));
+        (*node)->left = (*node)->right = NULL;
+        (*node)->val = val;
+        return;
+    }
+
+    if(compar(val, (*node)->val, ctx)<0)
+        sorted_list_insert(&(*node)->left, val, ctx, compar);
+    else if(compar(val, (*node)->val, ctx)>0)
+        sorted_list_insert(&(*node)->right, val, ctx, compar);
+    else; /*neglect if the same ns*/
+}
+
+void
+sorted_list_free_container(
+    c14n_sorted_list_t *root,
+    const axutil_env_t *env
+)
+{
+    if (!root) return;
+    if (root->left)
+    {
+        sorted_list_free_container(root->left, env);
+        AXIS2_FREE(env->allocator, root->left);
+    }
+    if (root->right)
+    {
+        sorted_list_free_container(root->right, env);
+        AXIS2_FREE(env->allocator, root->right);
+    }
+    /*if (root) AXIS2_FREE(env->allocator, root);*/
+}
+
+void
+sorted_list_free(
+    c14n_sorted_list_t *root,
+    void(*free)(const void *, const void *),
+    const axutil_env_t *env
+)
+{
+    sorted_list_iterate(root, NULL, free, env);
+}
+/*
+void print_str(const void* p)
+{
+    printf("%s\n", (char *)p);
+}
+ 
+void printout(c14n_sorted_list_t * sorted_list) 
+{
+    sorted_list_iterate(sorted_list, print_str);
+}
+ 
+static int
+cmpstringp(
+    const void *p1,
+    const void *p2
+    )
+{
+    return strcmp((char *) p1, (char *) p2);
+}
+ 
+ 
+int main() {
+   c14n_sorted_list_t * curr, * root;
+ 
+   root = c14n_sorted_list_create(curr);
+   char *c1 = "aaa";
+   char *c2 = "bac";
+   char *c3 = "aaaaaa";
+   char *c4 = "bab";
+   char *c5 = "aca";
+   char *c6 = "babaaa";
+ 
+   AXIS2_SORTED_LIST_INSERT(&root, (void *) c1, cmpstringp, env);
+   AXIS2_SORTED_LIST_INSERT(&root, (void *) c2, cmpstringp, env);
+   AXIS2_SORTED_LIST_INSERT(&root, (void *) c3, cmpstringp, env);
+   AXIS2_SORTED_LIST_INSERT(&root, (void *) c4, cmpstringp, env);
+   AXIS2_SORTED_LIST_INSERT(&root, (void *) c5, cmpstringp, env);
+   AXIS2_SORTED_LIST_INSERT(&root, (void *) c6, cmpstringp, env);
+   printout(root);
+   return 0;
+}
+ 
+*/