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 sh...@apache.org on 2008/04/08 14:37:26 UTC

svn commit: r645878 - in /webservices/rampart/trunk/c/src: core/mod_rampart.c handlers/rampart_in_handler.c handlers/rampart_out_handler.c

Author: shankar
Date: Tue Apr  8 05:37:25 2008
New Revision: 645878

URL: http://svn.apache.org/viewvc?rev=645878&view=rev
Log:
code formating and giving meaningful error messages.

Modified:
    webservices/rampart/trunk/c/src/core/mod_rampart.c
    webservices/rampart/trunk/c/src/handlers/rampart_in_handler.c
    webservices/rampart/trunk/c/src/handlers/rampart_out_handler.c

Modified: webservices/rampart/trunk/c/src/core/mod_rampart.c
URL: http://svn.apache.org/viewvc/webservices/rampart/trunk/c/src/core/mod_rampart.c?rev=645878&r1=645877&r2=645878&view=diff
==============================================================================
--- webservices/rampart/trunk/c/src/core/mod_rampart.c (original)
+++ webservices/rampart/trunk/c/src/core/mod_rampart.c Tue Apr  8 05:37:25 2008
@@ -20,18 +20,21 @@
 #include <axis2_conf_ctx.h>
 
 axis2_status_t AXIS2_CALL
-rampart_mod_shutdown(axis2_module_t *module,
-        const axutil_env_t *env);
+rampart_mod_shutdown(
+    axis2_module_t *module,
+    const axutil_env_t *env);
 
 axis2_status_t AXIS2_CALL
-rampart_mod_init(axis2_module_t *module,
-        const axutil_env_t *env,
-        axis2_conf_ctx_t *conf_ctx,
-        axis2_module_desc_t *module_desc);
+rampart_mod_init(
+    axis2_module_t *module,
+    const axutil_env_t *env,
+    axis2_conf_ctx_t *conf_ctx,
+    axis2_module_desc_t *module_desc);
 
 axis2_status_t AXIS2_CALL
-rampart_mod_fill_handler_create_func_map(axis2_module_t *module,
-        const axutil_env_t *env);
+rampart_mod_fill_handler_create_func_map(
+    axis2_module_t *module,
+    const axutil_env_t *env);
 
 static const axis2_module_ops_t addr_module_ops_var = {
     rampart_mod_init,
@@ -40,47 +43,56 @@
     };
 
 axis2_module_t *
-rampart_mod_create(const axutil_env_t *env)
+rampart_mod_create(
+    const axutil_env_t *env)
 {
     axis2_module_t *module = NULL;
-    /* Allocate memory for the module */
-    module = AXIS2_MALLOC(env->allocator,
-            sizeof(axis2_module_t));
+    module = AXIS2_MALLOC(env->allocator, sizeof(axis2_module_t));
+    if (!module)
+    {
+        AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE);
+        AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, 
+            "[rampart][rampart_mod] Not enough memory. Cannot create module.");
+        return NULL;
+    }
 
-    /* Set module operations*/
     module->ops = &addr_module_ops_var;
     return module;
 }
 
 axis2_status_t AXIS2_CALL
-rampart_mod_init(axis2_module_t *module,
-        const axutil_env_t *env,
-        axis2_conf_ctx_t *conf_ctx,
-        axis2_module_desc_t *module_desc)
+rampart_mod_init(
+    axis2_module_t *module,
+    const axutil_env_t *env,
+    axis2_conf_ctx_t *conf_ctx,
+    axis2_module_desc_t *module_desc)
 {
-    /* Any initialization stuff of Rampart module goes here. At the moment we have NONE. 
+    /* 
+     * Any initialization stuff of Rampart module goes here. At the moment we have NONE. 
      * Intialization happens in handlers depending on the message flow and policies
-     * */
+     */
     rampart_error_init();
     
-    AXIS2_LOG_INFO(env->log,"[rampart][rampart_mod] rampart_mod initialized");
+    AXIS2_LOG_INFO(env->log, 
+        "[rampart][rampart_mod] rampart_mod initialized");
     return AXIS2_SUCCESS;
 }
 
 axis2_status_t AXIS2_CALL
-rampart_mod_shutdown(axis2_module_t *module,
-        const axutil_env_t *env)
+rampart_mod_shutdown(
+    axis2_module_t *module,
+    const axutil_env_t *env)
 {
-    AXIS2_LOG_INFO(env->log,"[rampart][rampart_mod] rampart_mod shutdown");
-
-    if (module->handler_create_func_map)
-    {
-        axutil_hash_free(module->handler_create_func_map, env);
-        module->handler_create_func_map = NULL;
-    }
+    AXIS2_LOG_INFO(env->log,
+        "[rampart][rampart_mod] rampart_mod shutdown");
 
     if (module)
     {
+        if (module->handler_create_func_map)
+        {
+            axutil_hash_free(module->handler_create_func_map, env);
+            module->handler_create_func_map = NULL;
+        }
         AXIS2_FREE(env->allocator, module);
         module = NULL;
     }
@@ -88,23 +100,24 @@
 }
 
 axis2_status_t AXIS2_CALL
-rampart_mod_fill_handler_create_func_map(axis2_module_t *module,
-        const axutil_env_t *env)
+rampart_mod_fill_handler_create_func_map(
+    axis2_module_t *module,
+    const axutil_env_t *env)
 {
-    AXIS2_ENV_CHECK(env, AXIS2_FAILURE);
-
     module->handler_create_func_map = axutil_hash_make(env);
     if (!module->handler_create_func_map)
     {
-        AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NO_MEMORY,
-                AXIS2_FAILURE);
+        AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE);
+        AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, 
+            "[rampart][rampart_mod] Cannot create function map.");
         return AXIS2_FAILURE;
     }
 
-    /* Set Rampart Handlers
+    /*
+     * Set Rampart Handlers
      * 1. Rampart In Handler to process message
      * 2. Rampart Out Handler to build the message
-     * */
+     */
     axutil_hash_set(module->handler_create_func_map, RAMPART_IN_HANDLER, 
             AXIS2_HASH_KEY_STRING, rampart_in_handler_create);
 
@@ -118,13 +131,15 @@
  * Following block distinguish the exposed part of the dll.
  */
 AXIS2_EXPORT int
-axis2_get_instance(axis2_module_t **inst,
-        const axutil_env_t *env)
+axis2_get_instance(
+    axis2_module_t **inst,
+    const axutil_env_t *env)
 {
     *inst = rampart_mod_create(env);
     if (!(*inst))
     {
-        AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI,"[rampart][rampart_mod] Rampart module creation failed");
+        AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI,
+            "[rampart][rampart_mod] Rampart module creation failed");
         return AXIS2_FAILURE;
     }
 
@@ -132,8 +147,9 @@
 }
 
 AXIS2_EXPORT int
-axis2_remove_instance(axis2_module_t *inst,
-        const axutil_env_t *env)
+axis2_remove_instance(
+    axis2_module_t *inst,
+    const axutil_env_t *env)
 {
     axis2_status_t status = AXIS2_FAILURE;
     if (inst)

Modified: webservices/rampart/trunk/c/src/handlers/rampart_in_handler.c
URL: http://svn.apache.org/viewvc/webservices/rampart/trunk/c/src/handlers/rampart_in_handler.c?rev=645878&r1=645877&r2=645878&view=diff
==============================================================================
--- webservices/rampart/trunk/c/src/handlers/rampart_in_handler.c (original)
+++ webservices/rampart/trunk/c/src/handlers/rampart_in_handler.c Tue Apr  8 05:37:25 2008
@@ -35,27 +35,29 @@
 #include <rampart_sec_processed_result.h>
 #include <rampart_context.h>
 #include <rampart_engine.h>
-/*************************** Function headers *********************************/
 
 axis2_status_t AXIS2_CALL
-rampart_in_handler_invoke(struct axis2_handler *handler,
-                          const axutil_env_t *env,
-                          struct axis2_msg_ctx *msg_ctx);
-
-
-/**********************end of header functions ****************************/
+rampart_in_handler_invoke(
+    struct axis2_handler *handler,
+    const axutil_env_t *env,
+    struct axis2_msg_ctx *msg_ctx);
 
 AXIS2_EXTERN axis2_handler_t *AXIS2_CALL
-rampart_in_handler_create(const axutil_env_t *env,
-                          axutil_string_t *name)
+rampart_in_handler_create(
+    const axutil_env_t *env,
+    axutil_string_t *name)
 {
     axis2_handler_t *handler = NULL;
     AXIS2_ENV_CHECK(env, NULL);
+
     handler = axis2_handler_create(env);
     if (!handler)
     {
+        AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, 
+            "[rampart][rampart_in_handler] Cannot create in-handler.");
         return NULL;
     }
+
     /*Set the function to invoke*/
     axis2_handler_set_invoke(handler, env, rampart_in_handler_invoke);
     
@@ -64,36 +66,36 @@
 
 
 axis2_status_t AXIS2_CALL
-rampart_in_handler_invoke(struct axis2_handler *handler,
-                          const axutil_env_t *env,
-                          struct axis2_msg_ctx *msg_ctx)
+rampart_in_handler_invoke(
+    struct axis2_handler *handler,
+    const axutil_env_t *env,
+    struct axis2_msg_ctx *msg_ctx)
 {
     axiom_soap_envelope_t *soap_envelope = NULL;
     axiom_soap_header_t *soap_header = NULL;
     axis2_status_t status = AXIS2_FAILURE;
     axiom_node_t *sec_node = NULL;
     rampart_context_t *rampart_context = NULL;
-    /*axis2_bool_t serverside =  AXIS2_FALSE;*/
 
-    AXIS2_ENV_CHECK(env, AXIS2_FAILURE);
     AXIS2_PARAM_CHECK(env->error, msg_ctx, AXIS2_FAILURE);
 
-    /*since rampart in_handler is a global handler we should
-    first check whether the rampart module is engaged.If not engaged we 
-    should not process the message but return success.*/
-
-    /*This method is implemented in rampart_handler utils.*/
+    /*
+    * since rampart in_handler is a global handler we should
+    * first check whether the rampart module is engaged.If not engaged we 
+    * should not process the message but return success.
+    */
     if(!rampart_is_rampart_engaged(env, msg_ctx))
     {
-        AXIS2_LOG_INFO(env->log, "[rampart][rampart_in_handler] Rampart is not engaged. No security checks. ");
+        AXIS2_LOG_INFO(env->log, 
+            "[rampart][rampart_in_handler] Rampart is not engaged. No security checks needed. ");
         return AXIS2_SUCCESS;
     }
 
-
     soap_envelope =  axis2_msg_ctx_get_soap_envelope(msg_ctx, env);
     if(!soap_envelope)
     {
-        AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "[rampart][rampart_in_handler] No SOAP envelope found. ERROR");
+        AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, 
+            "[rampart][rampart_in_handler] SOAP envelope cannot be found.");
         return AXIS2_FAILURE;
     }
 
@@ -101,58 +103,47 @@
     if (!soap_header)
     {
         /*No SOAP header, so no point of proceeding. FAIL*/
-        AXIS2_LOG_INFO(env->log, "[rampart][rampart_in_handler] No SOAP header found.");
+        AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, 
+            "[rampart][rampart_in_handler] SOAP header cannot be found.");
         return AXIS2_FAILURE;
     }
-    AXIS2_LOG_TRACE(env->log, AXIS2_LOG_SI, "[rampart][rampart_in_handler] SOAP header found");
 
     rampart_context = rampart_engine_build_configuration(env, msg_ctx, AXIS2_TRUE);
-
     if(!rampart_context)
     {
-        AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "[rampart][rampart_in_handler] ramaprt_context creation failed.");
+        AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, 
+            "[rampart][rampart_in_handler] rampart_context creation failed.");
         return AXIS2_FAILURE;
     }
 
     sec_node = rampart_get_security_header(env, msg_ctx, soap_header);
 
     /*We do not check for the security header in Transport binding */
-    if((rampart_context_get_binding_type(rampart_context, env)) != RP_PROPERTY_TRANSPORT_BINDING)
+    if(rampart_context_get_binding_type(rampart_context, env) != RP_PROPERTY_TRANSPORT_BINDING)
     {
         if(!sec_node)
         {
-            AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI,
-                "[rampart][rampart_in_handler] No security header element.");
+            AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, 
+                "[rampart][rampart_in_handler] Security header cannot be found.");
             return AXIS2_FAILURE;
         }
     }
 
     status = rampart_set_security_processed_results_property(env, msg_ctx);
-
-    if(AXIS2_FAILURE == status)
+    if(status != AXIS2_SUCCESS)
     {
         AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI,
-            "[rampart][rampart_in_handler] Unable to set the security processed results");
+            "[rampart][rampart_in_handler] Unable to set the security processed results.");
+        return status;
     }
 
-    status = rampart_shp_process_sec_header(env, msg_ctx, rampart_context,
-                                             soap_envelope, sec_node);                                         
-
-    if(status!=AXIS2_SUCCESS)
+    status = rampart_shp_process_sec_header(env, msg_ctx, rampart_context, soap_envelope, sec_node);                                         
+    if(status != AXIS2_SUCCESS)
     {
         AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI,
-                        "[rampart][rampart_in_handler] Security Header processing failed.");
+            "[rampart][rampart_in_handler] Security Header processing failed.");
         return status;
     }
 
-    /*we don't need to clear the rampart context, since it is in the property map.
-    It will be freed when a new rampart context is assigned or when property map is freed*/
-    /*serverside = axis2_msg_ctx_get_server_side(msg_ctx,env);
-    if(!serverside)
-    {
-        rampart_context_free(rampart_context, env);
-        rampart_context = NULL;
-    }*/
-
-    return status;
+    return AXIS2_SUCCESS;
 }

Modified: webservices/rampart/trunk/c/src/handlers/rampart_out_handler.c
URL: http://svn.apache.org/viewvc/webservices/rampart/trunk/c/src/handlers/rampart_out_handler.c?rev=645878&r1=645877&r2=645878&view=diff
==============================================================================
--- webservices/rampart/trunk/c/src/handlers/rampart_out_handler.c (original)
+++ webservices/rampart/trunk/c/src/handlers/rampart_out_handler.c Tue Apr  8 05:37:25 2008
@@ -31,27 +31,26 @@
 #include <rampart_sec_header_builder.h>
 #include <rampart_context.h>
 #include <rampart_engine.h>
-/*********************** Function headers *********************************/
 
 AXIS2_EXTERN axis2_status_t AXIS2_CALL
-rampart_out_handler_invoke(struct axis2_handler *handler,
-                           const axutil_env_t * env,
-                           struct axis2_msg_ctx *msg_ctx);
-
-
-
-/**********************end of header functions ****************************/
+rampart_out_handler_invoke(
+    struct axis2_handler *handler,
+    const axutil_env_t * env,
+    struct axis2_msg_ctx *msg_ctx);
 
 AXIS2_EXTERN axis2_handler_t *AXIS2_CALL
-rampart_out_handler_create(const axutil_env_t *env,  axutil_string_t *name)
+rampart_out_handler_create(
+    const axutil_env_t *env,  
+    axutil_string_t *name)
 {
     axis2_handler_t *handler = NULL;
-
     AXIS2_ENV_CHECK(env, NULL);
 
     handler = axis2_handler_create(env);
     if (!handler)
     {
+        AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, 
+            "[rampart][rampart_out_handler] Cannot create out-handler.");
         return NULL;
     }
 
@@ -62,8 +61,10 @@
 }
 
 axis2_status_t AXIS2_CALL
-rampart_out_handler_invoke(struct axis2_handler * handler,
-                           const axutil_env_t * env, axis2_msg_ctx_t * msg_ctx)
+rampart_out_handler_invoke(
+    struct axis2_handler * handler,
+    const axutil_env_t * env, 
+    axis2_msg_ctx_t * msg_ctx)
 {
     axiom_soap_envelope_t *soap_envelope = NULL;
     axiom_soap_header_t *soap_header = NULL;
@@ -71,84 +72,69 @@
     axiom_element_t *soap_header_ele = NULL;
     axis2_status_t status = AXIS2_FAILURE;
     rampart_context_t *rampart_context = NULL;
-    axis2_bool_t serverside = AXIS2_FALSE;
 
-    AXIS2_ENV_CHECK(env, AXIS2_FAILURE);
     AXIS2_PARAM_CHECK(env->error, msg_ctx, AXIS2_FAILURE);
 
-    serverside = axis2_msg_ctx_get_server_side(msg_ctx,env);
+    /* 
+     * Since rampart out_handler is a global handler we should
+     * first check whether the rampart module is engaged.If not we
+     * should not process the message and return success.
+     */
+    if(!rampart_is_rampart_engaged(env,msg_ctx))
+    {
+        AXIS2_LOG_INFO(env->log, 
+            "[rampart][rampart_out_handler] Rampart is not engaged. No security support is needed.");
+        return AXIS2_SUCCESS;
+    }
+
     soap_envelope =  axis2_msg_ctx_get_soap_envelope(msg_ctx, env);
     if (!soap_envelope)
     {
-        AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "[rampart][rampart_out_handler] No SOAP envelope found. ERROR");
+        AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, 
+            "[rampart][rampart_out_handler] SOAP envelope cannot be found.");
         return AXIS2_FAILURE;
     }
 
-    /* We are checking for the soap header element*/
     soap_header  = axiom_soap_envelope_get_header(soap_envelope, env);
-
     if (!soap_header)
     {
-        AXIS2_LOG_INFO(env->log, "[rampart][rampart_out_handler] No SOAP header found. ERROR");
-        /*No SOAP header, so no point of proceeding*/
-        return AXIS2_SUCCESS;
+        /*No SOAP header, so no point of proceeding. FAIL*/
+        AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, 
+            "[rampart][rampart_out_handler] SOAP header cannot be found.");
+        return AXIS2_FAILURE;
+    }
+
+    soap_header_node = axiom_soap_header_get_base_node(soap_header, env);
+    if(!soap_header_node)
+    {
+        AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, 
+            "[rampart][rampart_out_handler] Cannot get soap header node.");
+        return AXIS2_FAILURE;
+    }
+
+    soap_header_ele = (axiom_element_t *)axiom_node_get_data_element(soap_header_node,env);
+    if(!soap_header_ele)
+    {
+        AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, 
+            "[rampart][rampart_out_handler] Cannot get soap header element.");
+        return AXIS2_FAILURE;
+    }
+
+    rampart_context = rampart_engine_build_configuration(env, msg_ctx, AXIS2_FALSE);
+    if(!rampart_context)
+    {
+        AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, 
+            "[rampart][rampart_out_handler] ramaprt_context creation failed.");
+        return AXIS2_FAILURE;
     }
 
-    /* If the soap header is available then add the security header*/
-    if (soap_header)
+    status = rampart_shb_build_message(env, msg_ctx, rampart_context, soap_envelope);
+    if(status != AXIS2_SUCCESS)
     {
-        soap_header_node = axiom_soap_header_get_base_node(soap_header, env);
-        if(!soap_header_node)
-        {
-            AXIS2_LOG_INFO(env->log, "[rampart][rampart_out_handler] Cannot Create the header node");
-            /*No SOAP header, so no point of proceeding*/
-            return AXIS2_SUCCESS;
-        }
-        soap_header_ele = (axiom_element_t *)axiom_node_get_data_element(soap_header_node,env);
-
-        /* Since rampart out_handler is a global handler we should
-         * first check whether the rampart module is engaged.If not we
-         * should not process the message and return success.
-         * */
-
-        /* Is rampart engaged? Just checking*/
-        if(!rampart_is_rampart_engaged(env,msg_ctx))
-        {
-            AXIS2_LOG_INFO(env->log, "[rampart][rampart_out_handler] Ramart is not engaged. No security support");
-            return AXIS2_SUCCESS;
-        }
-
-        /* Build configurations
-         * 1. Load policies
-         * 2. Create rampart context
-         * 3. Set policies to define ramprat behaviuor 
-         * */
-        rampart_context = rampart_engine_build_configuration(env, msg_ctx, AXIS2_FALSE);
-
-        if(!rampart_context)
-        {
-            AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "[rampart][rampart_out_handler] ramaprt_context creation failed.");
-            return AXIS2_FAILURE;
-        }
-
-        /* We call the security header builder.
-         * Based on security policies we build the message.
-         * Encrypt/Sign/UT/TS/Attach Key Info etc.*/
-        status = rampart_shb_build_message(env, msg_ctx, rampart_context, soap_envelope);
-        if(AXIS2_FAILURE == status){
-            AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI,
-                           "[rampart][rampart_out_handler] Security header building failed ERROR");
-            return AXIS2_FAILURE;
-        }
-        
-        /*we don't need to clear the rampart context, since it is in the property map.
-        It will be freed when a new rampart context is assigned or when property map is freed*/
-       /* if(serverside)
-        {
-            rampart_context_free(rampart_context, env);
-            rampart_context = NULL;
-        }*/
+        AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI,
+            "[rampart][rampart_out_handler] Security header building failed.");
+        return status;
     }
 
-    return status;
+    return AXIS2_SUCCESS;
 }