You are viewing a plain text version of this content. The canonical link for it is here.
Posted to axis-cvs@ws.apache.org by ma...@apache.org on 2008/07/31 06:42:19 UTC
svn commit: r681275 - in /webservices/axis2/trunk/c/neethi:
include/neethi_policy.h src/engine.c src/policy.c
test/policies/symmetric_binding_policy.xml test/test.c
Author: manjula
Date: Wed Jul 30 21:42:18 2008
New Revision: 681275
URL: http://svn.apache.org/viewvc?rev=681275&view=rev
Log:
Fixing Axis2C-1245.
Modified:
webservices/axis2/trunk/c/neethi/include/neethi_policy.h
webservices/axis2/trunk/c/neethi/src/engine.c
webservices/axis2/trunk/c/neethi/src/policy.c
webservices/axis2/trunk/c/neethi/test/policies/symmetric_binding_policy.xml
webservices/axis2/trunk/c/neethi/test/test.c
Modified: webservices/axis2/trunk/c/neethi/include/neethi_policy.h
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/c/neethi/include/neethi_policy.h?rev=681275&r1=681274&r2=681275&view=diff
==============================================================================
--- webservices/axis2/trunk/c/neethi/include/neethi_policy.h (original)
+++ webservices/axis2/trunk/c/neethi/include/neethi_policy.h Wed Jul 30 21:42:18 2008
@@ -117,6 +117,18 @@
const axutil_env_t * env,
axiom_node_t * root_node);
+ AXIS2_EXTERN axutil_hash_t *AXIS2_CALL
+ neethi_policy_get_attributes(
+ neethi_policy_t *neethi_policy,
+ const axutil_env_t *env);
+
+ AXIS2_EXTERN axis2_status_t AXIS2_CALL
+ neethi_policy_set_attributes(
+ neethi_policy_t *neethi_policy,
+ const axutil_env_t *env,
+ axutil_hash_t *attributes);
+
+
/** @} */
#ifdef __cplusplus
}
Modified: webservices/axis2/trunk/c/neethi/src/engine.c
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/c/neethi/src/engine.c?rev=681275&r1=681274&r2=681275&view=diff
==============================================================================
--- webservices/axis2/trunk/c/neethi/src/engine.c (original)
+++ webservices/axis2/trunk/c/neethi/src/engine.c Wed Jul 30 21:42:18 2008
@@ -17,6 +17,7 @@
#include <neethi_engine.h>
#include <neethi_assertion_builder.h>
+#include <axiom_attribute.h>
/*Private functions*/
@@ -75,6 +76,11 @@
neethi_exactlyone_t *exactlyone2,
const axutil_env_t *env);
+static void neethi_engine_clear_element_attributes(
+ axutil_hash_t *attr_hash,
+ const axutil_env_t *env);
+
+
/*Implementations*/
/*This is the function which is called from outside*/
@@ -84,9 +90,9 @@
const axutil_env_t *env,
axiom_node_t *node,
axiom_element_t *element)
- {
- return get_operator_neethi_policy(env, node, element);
- }
+{
+ return get_operator_neethi_policy(env, node, element);
+}
neethi_all_t *AXIS2_CALL
get_operator_all(
@@ -285,41 +291,66 @@
*comes here.Following is a little hack until we implement attribute
hash map logic.*/
- axis2_char_t *id = NULL;
- axutil_qname_t *qname = NULL;
- axis2_char_t *name = NULL;
-
- qname =
- axutil_qname_create(env, NEETHI_ID, NEETHI_WSU_NS,
- NULL/*NEETHI_WSU_NS_PREFIX*/);
- if (!qname)
- {
- AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE);
- AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Out of memory");
- return AXIS2_FAILURE;
- }
- id = axiom_element_get_attribute_value(element, env, qname);
- axutil_qname_free(qname, env);
- qname = NULL;
+ axutil_hash_t *attributes = axiom_element_extract_attributes(
+ element, env, node);
- qname = axutil_qname_create(env, NEETHI_NAME, NULL, NULL);
- if (!qname)
+ if(attributes)
{
- AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE);
- AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Out of memory");
- return AXIS2_FAILURE;
- }
- name = axiom_element_get_attribute_value(element, env, qname);
- axutil_qname_free(qname, env);
- qname = NULL;
+ axutil_hash_index_t *hi = NULL;
+
+ axutil_hash_t *ht = neethi_policy_get_attributes(
+ (neethi_policy_t *)value, env);
- if (id)
- {
- neethi_policy_set_id((neethi_policy_t *) value, env, id);
- }
- if (name)
- {
- neethi_policy_set_name((neethi_policy_t *) value, env, name);
+ if(!ht)
+ {
+ AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI,
+ "[neethi] Policy hash map creation failed.");
+ return AXIS2_FAILURE;
+ }
+
+
+ for (hi = axutil_hash_first(attributes, env);
+ hi; hi = axutil_hash_next(env, hi))
+ {
+ axis2_char_t *key = NULL;
+ void *val = NULL;
+ axutil_qname_t *qname = NULL;
+ axis2_char_t *attr_val = NULL;
+ axiom_namespace_t *ns = NULL;
+ axis2_char_t *ns_uri = NULL;
+ axiom_attribute_t *om_attr = NULL;
+
+ axutil_hash_this(hi, NULL, NULL, &val);
+ if(val)
+ {
+ om_attr = (axiom_attribute_t *) val;
+ ns = axiom_attribute_get_namespace(om_attr, env);
+ if(ns)
+ {
+ ns_uri = axiom_namespace_get_uri(ns, env);
+ }
+
+ qname = axutil_qname_create(env,
+ axiom_attribute_get_localname(om_attr, env),
+ ns_uri, NULL);
+ if(qname)
+ {
+ key = axutil_qname_to_string(qname, env);
+ if(key)
+ {
+ attr_val = axiom_attribute_get_value(om_attr, env);
+ if(attr_val)
+ {
+ axutil_hash_set(ht, axutil_strdup(env,key), AXIS2_HASH_KEY_STRING,
+ axutil_strdup(env, attr_val));
+ }
+ }
+ axutil_qname_free(qname, env);
+ }
+ }
+ }
+ neethi_engine_clear_element_attributes(attributes, env);
+ attributes = NULL;
}
}
@@ -1306,3 +1337,25 @@
return neethi_policy_serialize(policy, NULL, env);
}
+
+static void neethi_engine_clear_element_attributes(
+ axutil_hash_t *attr_hash,
+ const axutil_env_t *env)
+{
+ axutil_hash_index_t *hi = NULL;
+
+ for(hi = axutil_hash_first(attr_hash, env); hi; hi = axutil_hash_next(env, hi))
+ {
+ void *val = NULL;
+ axutil_hash_this(hi, NULL, NULL, &val);
+ if (val)
+ {
+ axiom_attribute_free((axiom_attribute_t *)val, env);
+ val = NULL;
+ }
+ }
+ axutil_hash_free(attr_hash, env);
+ attr_hash = NULL;
+
+ return;
+}
Modified: webservices/axis2/trunk/c/neethi/src/policy.c
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/c/neethi/src/policy.c?rev=681275&r1=681274&r2=681275&view=diff
==============================================================================
--- webservices/axis2/trunk/c/neethi/src/policy.c (original)
+++ webservices/axis2/trunk/c/neethi/src/policy.c Wed Jul 30 21:42:18 2008
@@ -17,15 +17,21 @@
#include <neethi_policy.h>
#include <neethi_engine.h>
+#include <axiom_attribute.h>
+
struct neethi_policy_t
{
axutil_array_list_t *policy_components;
- axis2_char_t *name;
- axis2_char_t *id;
+ axutil_hash_t *attributes;
axiom_node_t *root_node;
};
+static void neethi_policy_clear_attributes(
+ axutil_hash_t *attributes,
+ const axutil_env_t *env);
+
+
AXIS2_EXTERN neethi_policy_t *AXIS2_CALL
neethi_policy_create(
const axutil_env_t * env)
@@ -53,8 +59,7 @@
AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Out of memory");
return NULL;
}
- neethi_policy->name = NULL;
- neethi_policy->id = NULL;
+ neethi_policy->attributes = axutil_hash_make(env);
neethi_policy->root_node = NULL;
return neethi_policy;
@@ -86,7 +91,7 @@
axutil_array_list_free(neethi_policy->policy_components, env);
neethi_policy->policy_components = NULL;
}
- if (neethi_policy->id)
+ /*if (neethi_policy->id)
{
AXIS2_FREE(env->allocator, neethi_policy->id);
neethi_policy->id = NULL;
@@ -95,7 +100,14 @@
{
AXIS2_FREE(env->allocator, neethi_policy->name);
neethi_policy->name = NULL;
+ }*/
+ if(neethi_policy->attributes)
+ {
+ neethi_policy_clear_attributes(neethi_policy->attributes,
+ env);
+ neethi_policy->attributes = NULL;
}
+
if (neethi_policy->root_node)
{
axiom_node_free_tree(neethi_policy->root_node, env);
@@ -107,6 +119,31 @@
return;
}
+
+static void neethi_policy_clear_attributes(
+ axutil_hash_t *attributes,
+ const axutil_env_t *env)
+{
+ if(attributes)
+ {
+ axutil_hash_index_t *hi = NULL;
+ void *val = NULL;
+
+ for (hi = axutil_hash_first(attributes, env); hi;
+ hi = axutil_hash_next(env, hi))
+ {
+ axutil_hash_this(hi, NULL, NULL, &val);
+
+ if (val)
+ {
+ AXIS2_FREE(env->allocator, (axis2_char_t *)val);
+ val = NULL;
+ }
+ }
+ axutil_hash_free(attributes, env);
+ attributes = NULL;
+ }
+}
/* Implementations */
AXIS2_EXTERN axutil_array_list_t *AXIS2_CALL
@@ -212,34 +249,151 @@
neethi_policy_t *neethi_policy,
const axutil_env_t *env)
{
- return neethi_policy->name;
+ if(neethi_policy->attributes)
+ {
+ axutil_qname_t *qname = NULL;
+ qname = axutil_qname_create(env, NEETHI_NAME, NULL, NULL);
+
+ if(qname)
+ {
+ axis2_char_t *key = axutil_qname_to_string(qname, env);
+ if(key)
+ {
+ return (axis2_char_t *)axutil_hash_get(neethi_policy->attributes, key,
+ AXIS2_HASH_KEY_STRING);
+ }
+ else
+ {
+ return NULL;
+ }
+ }
+ else
+ {
+ return NULL;
+ }
+ }
+ else
+ {
+ return NULL;
+ }
}
-AXIS2_EXTERN axis2_status_t AXIS2_CALL
-neethi_policy_set_name(
+
+AXIS2_EXTERN axis2_char_t *AXIS2_CALL
+neethi_policy_get_id(
neethi_policy_t *neethi_policy,
- const axutil_env_t *env,
- axis2_char_t *name)
+ const axutil_env_t *env)
{
- neethi_policy->name = name;
- return AXIS2_SUCCESS;
+ if(neethi_policy->attributes)
+ {
+ axis2_char_t *id = NULL;
+ axutil_qname_t *qname = NULL;
+ qname = axutil_qname_create(env, NEETHI_ID, NEETHI_WSU_NS, NULL);
+
+ if(qname)
+ {
+ axis2_char_t *key = axutil_qname_to_string(qname, env);
+ if(key)
+ {
+ id = (axis2_char_t *)axutil_hash_get(neethi_policy->attributes, key,
+ AXIS2_HASH_KEY_STRING);
+ }
+ axutil_qname_free(qname, env);
+ qname = NULL;
+ return id;
+ }
+ else
+ {
+ return NULL;
+ }
+ }
+ else
+ {
+ return NULL;
+ }
}
-AXIS2_EXTERN axis2_char_t *AXIS2_CALL
-neethi_policy_get_id(
+
+AXIS2_EXTERN axis2_status_t AXIS2_CALL
+ neethi_policy_set_id(
+ neethi_policy_t * neethi_policy,
+ const axutil_env_t * env,
+ axis2_char_t * id)
+{
+ axutil_qname_t *qname = NULL;
+ axis2_char_t *key = NULL;
+
+ qname = axutil_qname_create(env, NEETHI_ID, NEETHI_WSU_NS, NULL);
+
+ if(qname)
+ {
+ key = axutil_qname_to_string(qname, env);
+ if(key)
+ {
+ axutil_hash_set(neethi_policy->attributes, key,
+ AXIS2_HASH_KEY_STRING, axutil_strdup(env, id));
+ }
+ axutil_qname_free(qname, env);
+ return AXIS2_SUCCESS;
+ }
+ else
+ {
+ return AXIS2_FAILURE;
+ }
+}
+
+
+AXIS2_EXTERN axis2_status_t AXIS2_CALL
+ neethi_policy_set_name(
+ neethi_policy_t * neethi_policy,
+ const axutil_env_t * env,
+ axis2_char_t * name)
+{
+ axutil_qname_t *qname = NULL;
+ axis2_char_t *key = NULL;
+
+ qname = axutil_qname_create(env, NEETHI_NAME, NULL, NULL);
+
+ if(qname)
+ {
+ key = axutil_qname_to_string(qname, env);
+ if(key)
+ {
+ axutil_hash_set(neethi_policy->attributes, key,
+ AXIS2_HASH_KEY_STRING, axutil_strdup(env, name));
+ }
+ axutil_qname_free(qname, env);
+ return AXIS2_SUCCESS;
+ }
+ else
+ {
+ return AXIS2_FAILURE;
+ }
+}
+
+
+AXIS2_EXTERN axutil_hash_t *AXIS2_CALL
+neethi_policy_get_attributes(
neethi_policy_t *neethi_policy,
const axutil_env_t *env)
{
- return neethi_policy->id;
+ return neethi_policy->attributes;
}
AXIS2_EXTERN axis2_status_t AXIS2_CALL
-neethi_policy_set_id(
+neethi_policy_set_attributes(
neethi_policy_t *neethi_policy,
const axutil_env_t *env,
- axis2_char_t *id)
+ axutil_hash_t *attributes)
{
- neethi_policy->id = axutil_strdup(env, id);
+ if(neethi_policy->attributes)
+ {
+ neethi_policy_clear_attributes(neethi_policy->attributes,
+ env);
+ neethi_policy->attributes = NULL;
+ }
+
+ neethi_policy->attributes = attributes;
return AXIS2_SUCCESS;
}
Modified: webservices/axis2/trunk/c/neethi/test/policies/symmetric_binding_policy.xml
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/c/neethi/test/policies/symmetric_binding_policy.xml?rev=681275&r1=681274&r2=681275&view=diff
==============================================================================
--- webservices/axis2/trunk/c/neethi/test/policies/symmetric_binding_policy.xml (original)
+++ webservices/axis2/trunk/c/neethi/test/policies/symmetric_binding_policy.xml Wed Jul 30 21:42:18 2008
@@ -1,4 +1,4 @@
-<wsp:Policy xmlns:wsp="http://schemas.xmlsoap.org/ws/2004/09/policy">
+<wsp:Policy wsu:Id="SymmetricKeyPolicy" xmlns:wsp="http://schemas.xmlsoap.org/ws/2004/09/policy" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
<wsp:ExactlyOne>
<wsp:All>
<sp:SymmetricBinding xmlns:sp="http://schemas.xmlsoap.org/ws/2005/07/securitypolicy">
Modified: webservices/axis2/trunk/c/neethi/test/test.c
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/c/neethi/test/test.c?rev=681275&r1=681274&r2=681275&view=diff
==============================================================================
--- webservices/axis2/trunk/c/neethi/test/test.c (original)
+++ webservices/axis2/trunk/c/neethi/test/test.c Wed Jul 30 21:42:18 2008
@@ -76,6 +76,27 @@
return 0;
}
+ if(neethi_policy)
+ {
+ axis2_char_t *id = NULL;
+ axis2_char_t *name = NULL;
+
+ id = neethi_policy_get_id(neethi_policy, env);
+ if(id)
+ {
+ printf("Id is : %s\n", id);
+ }
+ name = neethi_policy_get_name(neethi_policy, env);
+ if(name)
+ {
+ printf("Name is : %s\n", name);
+ }
+ neethi_policy_free(neethi_policy, env);
+ neethi_policy = NULL;
+
+ printf("Successful \n");
+ }
+
/*else
{
axiom_node_t *s_node = NULL;