<commit_before>/*
 * 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_policy_include.h>
#include <neethi_policy.h>
#include <neethi_engine.h>

struct axis2_policy_include
{
    neethi_policy_t *policy;

    neethi_policy_t *effective_policy;

    neethi_registry_t *registry;

    axis2_desc_t *desc;

    axutil_hash_t *wrapper_elements;
};

typedef struct axis2_policy_wrapper
{
    int type;
    void *value;
} axis2_policy_wrapper_t;


AXIS2_EXTERN axis2_policy_include_t *AXIS2_CALL
axis2_policy_include_create(const axutil_env_t *env)
{
    axis2_policy_include_t *policy_include = NULL;

    AXIS2_ENV_CHECK(env, NULL);

    policy_include = (axis2_policy_include_t *) AXIS2_MALLOC(env->allocator,
        sizeof(axis2_policy_include_t));

    if (!policy_include)
    {
        AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE);
        return NULL;
    }

    policy_include->policy = NULL;
    policy_include->effective_policy = NULL;
    policy_include->registry = NULL;
    policy_include->desc = NULL;
    policy_include->wrapper_elements = NULL;

    policy_include->registry = neethi_registry_create(env);
    if (!policy_include->registry)
    {
        axis2_policy_include_free(policy_include, env);
        AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE);
        return NULL;
    }

    policy_include->wrapper_elements = axutil_hash_make(env);
    if (!policy_include->wrapper_elements)
    {
        axis2_policy_include_free(policy_include, env);
        AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE);
        return NULL;
    }

    return policy_include;
}

AXIS2_EXTERN axis2_policy_include_t *AXIS2_CALL
axis2_policy_include_create_with_desc(const axutil_env_t *env,
    axis2_desc_t *desc)
{
    axis2_policy_include_t *policy_include = NULL;
    axis2_desc_t *parent_desc = NULL;

    AXIS2_ENV_CHECK(env, NULL);

    policy_include = (axis2_policy_include_t *) axis2_policy_include_create(env);
    
    parent_desc = axis2_desc_get_parent(desc, env);
    
    if (policy_include->registry)
    {
        neethi_registry_free(policy_include->registry, env);
        policy_include->registry = NULL;
    }

    if (parent_desc)
    {
        axis2_policy_include_t *preant_policy_include = 
            axis2_desc_get_policy_include(parent_desc, env);
        if (preant_policy_include)
        {
            policy_include->registry = neethi_registry_create_with_parent(env, 
                axis2_policy_include_get_registry(preant_policy_include, env));
        }
        else
        {
            policy_include->registry = neethi_registry_create(env);
        }
    }
    else
    {
        policy_include->registry = neethi_registry_create(env);
    }
    
    policy_include->desc = desc;
    
    return policy_include;
}

AXIS2_EXTERN void AXIS2_CALL
axis2_policy_include_free(
    axis2_policy_include_t *policy_include,
    const axutil_env_t *env)
{
    AXIS2_ENV_CHECK(env, void);

    if (policy_include->registry)
    {
        neethi_registry_free(policy_include->registry, env);
    }

    if (policy_include->wrapper_elements)
    {
        axutil_hash_free(policy_include->wrapper_elements, env);
    }

    if (policy_include)
    {
        AXIS2_FREE(env->allocator, policy_include);
    }

    return;
}

AXIS2_EXTERN axis2_status_t AXIS2_CALL
axis2_policy_include_set_registry(axis2_policy_include_t *policy_include,
    const axutil_env_t *env, <commit_msg>Freeing the policy_wrapper hash element by element.<commit_after>/*
 * 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_policy_include.h>
#include <neethi_policy.h>
#include <neethi_engine.h>

struct axis2_policy_include
{
    neethi_policy_t *policy;

    neethi_policy_t *effective_policy;

    neethi_registry_t *registry;

    axis2_desc_t *desc;

    axutil_hash_t *wrapper_elements;
};

typedef struct axis2_policy_wrapper
{
    int type;
    void *value;
} axis2_policy_wrapper_t;


AXIS2_EXTERN axis2_policy_include_t *AXIS2_CALL
axis2_policy_include_create(const axutil_env_t *env)
{
    axis2_policy_include_t *policy_include = NULL;

    AXIS2_ENV_CHECK(env, NULL);

    policy_include = (axis2_policy_include_t *) AXIS2_MALLOC(env->allocator,
        sizeof(axis2_policy_include_t));

    if (!policy_include)
    {
        AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE);
        return NULL;
    }

    policy_include->policy = NULL;
    policy_include->effective_policy = NULL;
    policy_include->registry = NULL;
    policy_include->desc = NULL;
    policy_include->wrapper_elements = NULL;

    policy_include->registry = neethi_registry_create(env);
    if (!policy_include->registry)
    {
        axis2_policy_include_free(policy_include, env);
        AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE);
        return NULL;
    }

    policy_include->wrapper_elements = axutil_hash_make(env);
    if (!policy_include->wrapper_elements)
    {
        axis2_policy_include_free(policy_include, env);
        AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE);
        return NULL;
    }

    return policy_include;
}

AXIS2_EXTERN axis2_policy_include_t *AXIS2_CALL
axis2_policy_include_create_with_desc(const axutil_env_t *env,
    axis2_desc_t *desc)
{
    axis2_policy_include_t *policy_include = NULL;
    axis2_desc_t *parent_desc = NULL;

    AXIS2_ENV_CHECK(env, NULL);

    policy_include = (axis2_policy_include_t *) axis2_policy_include_create(env);
    
    parent_desc = axis2_desc_get_parent(desc, env);
    
    if (policy_include->registry)
    {
        neethi_registry_free(policy_include->registry, env);
        policy_include->registry = NULL;
    }

    if (parent_desc)
    {
        axis2_policy_include_t *preant_policy_include = 
            axis2_desc_get_policy_include(parent_desc, env);
        if (preant_policy_include)
        {
            policy_include->registry = neethi_registry_create_with_parent(env, 
                axis2_policy_include_get_registry(preant_policy_include, env));
        }
        else
        {
            policy_include->registry = neethi_registry_create(env);
        }
    }
    else
    {
        policy_include->registry = neethi_registry_create(env);
    }
    
    policy_include->desc = desc;
    
    return policy_include;
}

AXIS2_EXTERN void AXIS2_CALL
axis2_policy_include_free(
    axis2_policy_include_t *policy_include,
    const axutil_env_t *env)
{
    AXIS2_ENV_CHECK(env, void);

    if (policy_include->registry)
    {
        neethi_registry_free(policy_include->registry, env);
    }

    if (policy_include->wrapper_elements)
    {
        axutil_hash_index_t *hi = NULL;
        void *val = NULL;
        for (hi = axutil_hash_first(policy_include->wrapper_elements, env); hi;
                hi = axutil_hash_next(env, hi))
        {
            axis2_policy_wrapper_t *wrapper = NULL;
            axutil_hash_this(hi, NULL, NULL, &val);
            wrapper = (axis2_policy_wrapper_t *) val;
            if (wrapper)
                 AXIS2_FREE(env->allocator, wrapper);
            val = NULL;
            wrapper = NULL;
        }
        axutil_hash_free(policy_include->wrapper_elements, env);
    }

    if (policy_include)
    {
        AXIS2_FREE(env->allocator, policy_include);
    }

    return;
}

AXIS2_EXTERN axis2_status_t AXIS2_CALL
axis2_policy_include_set_registry(axis2_policy_include_t *policy_include,
    const axutil_env_t *env, 
{'fraction_non_alphanumeric': 0.0791023219642262, 'fraction_numerical': 0.012331963115209421, 'mean_word_length': 3.4214145383104126, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 61, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3089493', 'n_tokens_mistral': 2966, 'n_tokens_neox': 2887, 'n_words': 592}