<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_conf_init.h>
#include <axis2_transport_sender.h>
#include <axis2_transport_receiver.h>
#include <axis2_const.h>
#include <axutil_error.h>
#include <axutil_allocator.h>
#include <axutil_class_loader.h>
#include <axis2_dep_engine.h>
#include <axis2_module.h>

#define DEFAULT_REPO_PATH "."

axis2_status_t AXIS2_CALL
axis2_init_modules(
    const axutil_env_t * env,
    axis2_conf_ctx_t * conf_ctx);

static axis2_status_t AXIS2_CALL
axis2_load_services(
    const axutil_env_t * env,
    axis2_conf_ctx_t * conf_ctx);

axis2_status_t AXIS2_CALL
axis2_init_transports(
    const axutil_env_t * env,
    axis2_conf_ctx_t * conf_ctx);

static axis2_conf_ctx_t *AXIS2_CALL
axis2_build_conf_ctx_with_dep_engine(
    const axutil_env_t * env,
    axis2_dep_engine_t *dep_engine,
    axis2_char_t *is_server_side)
{
    axis2_conf_ctx_t *conf_ctx = NULL;
    axis2_conf_t *conf = NULL;
    axutil_property_t *property = NULL;
    axis2_ctx_t *conf_ctx_base = NULL;

    conf = axis2_dep_engine_load(dep_engine, env);
    if(!conf)
    {
        AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Loading deployment engine failed");
        axis2_dep_engine_free(dep_engine, env);
        return NULL;
    }
    axis2_conf_set_dep_engine(conf, env, dep_engine);

    conf_ctx = axis2_conf_ctx_create(env, conf);
    if(!conf_ctx)
    {
        AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Creating Axis2 configuration context failed.");
        return NULL;
    }
    axis2_conf_ctx_set_root_dir(conf_ctx, env, axis2_dep_engine_get_repos_path(dep_engine, env));

    conf_ctx_base = axis2_conf_ctx_get_base(conf_ctx, env);
    property = axutil_property_create_with_args(env, 2, 0, 0, is_server_side);
    axis2_ctx_set_property(conf_ctx_base, env, AXIS2_IS_SVR_SIDE, property);

    axis2_init_modules(env, conf_ctx);
    axis2_init_transports(env, conf_ctx);

    if(!axutil_strcmp(is_server_side, AXIS2_VALUE_TRUE))
    {
        axis2_load_services(env, conf_ctx);
    }

    return conf_ctx;
}

AXIS2_EXTERN axis2_conf_ctx_t *AXIS2_CALL
axis2_build_conf_ctx(
    const axutil_env_t * env,
    const axis2_char_t * repo_name)
{
    axis2_conf_ctx_t *conf_ctx = NULL;
    axis2_dep_engine_t *dep_engine = NULL;

    AXIS2_LOG_TRACE(env->log, AXIS2_LOG_SI, "Entry:axis2_build_conf_ctx");
    dep_engine = axis2_dep_engine_create_with_repos_name(env, repo_name);
    if(!dep_engine)
    {
        AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI,
            "Creating deployment engine failed for repository %s", repo_name);
        return NULL;
    }

    conf_ctx = axis2_build_conf_ctx_with_dep_engine(env, dep_engine, AXIS2_VALUE_TRUE);
    if(!conf_ctx)
    {
        AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI,
            "Loading configuration context failed for repository %s.", repo_name);
        return NULL;
    }

    AXIS2_LOG_TRACE(env->log, AXIS2_LOG_SI, "Exit:axis2_build_conf_ctx");
    return conf_ctx;
}

AXIS2_EXTERN axis2_conf_ctx_t *AXIS2_CALL
axis2_build_conf_ctx_with_file(
    const axutil_env_t * env,
    const axis2_char_t * file)
{
    axis2_conf_ctx_t *conf_ctx = NULL;
    axis2_dep_engine_t *dep_engine = NULL;

    AXIS2_LOG_TRACE(env->log, AXIS2_LOG_SI, "Entry:axis2_build_conf_ctx_with_file");
    dep_engine = axis2_dep_engine_create_with_axis2_xml(env, file);
    if(!dep_engine)
    {
        AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI,
            "Creating deployment engine for given Axis2 configuration file"
                "(axis2.xml) failed");
        return NULL;
    }

    conf_ctx = axis2_build_conf_ctx_with_dep_engine(env, dep_engine, AXIS2_VALUE_TRUE);
    if(!conf_ctx)
    {
        AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI,
            "Loading configuration context failed for given Axis2 configuration %s.", file);
        return NULL;
    }

    AXIS2_LOG_TRACE(env->log, AXIS2_LOG_SI, "Exit:axis2_build_conf_ctx_with_file");
    return conf_ctx;
}

axis2_conf_ctx_t *AXIS2_CALL
axis2_build_client_conf_ctx(
    const axutil_env_t * env,
    const axis2_char_t * axis2_home)
{
    axis2_conf_ctx_t *conf_ctx = NULL;
    axis2_dep_engine_t *dep_engine = NULL;
    axis2_conf_t *conf = NULL;
    axutil_property_t *property = NULL;
    axis2_ctx_t *conf_ctx_base = NULL;

    axis2_status_t status;
    unsigned int len = 0;

    AXIS2_LOG_TRACE(env->log, AXIS2_LOG_SI, "Entry:axis2_build_client_conf_ctx");<commit_msg>build_conf_ctx_with_file function bug fixed<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_conf_init.h>
#include <axis2_transport_sender.h>
#include <axis2_transport_receiver.h>
#include <axis2_const.h>
#include <axutil_error.h>
#include <axutil_allocator.h>
#include <axutil_class_loader.h>
#include <axis2_dep_engine.h>
#include <axis2_module.h>

#define DEFAULT_REPO_PATH "."

axis2_status_t AXIS2_CALL
axis2_init_modules(
    const axutil_env_t * env,
    axis2_conf_ctx_t * conf_ctx);

static axis2_status_t AXIS2_CALL
axis2_load_services(
    const axutil_env_t * env,
    axis2_conf_ctx_t * conf_ctx);

axis2_status_t AXIS2_CALL
axis2_init_transports(
    const axutil_env_t * env,
    axis2_conf_ctx_t * conf_ctx);

static axis2_conf_ctx_t *AXIS2_CALL
axis2_build_conf_ctx_with_dep_engine(
    const axutil_env_t * env,
    axis2_dep_engine_t *dep_engine,
    axis2_char_t *is_server_side)
{
    axis2_conf_ctx_t *conf_ctx = NULL;
    axis2_conf_t *conf = NULL;
    axutil_property_t *property = NULL;
    axis2_ctx_t *conf_ctx_base = NULL;

    conf = axis2_dep_engine_load(dep_engine, env);
    if(!conf)
    {
        AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Loading deployment engine failed");
        axis2_dep_engine_free(dep_engine, env);
        return NULL;
    }
    axis2_conf_set_dep_engine(conf, env, dep_engine);

    conf_ctx = axis2_conf_ctx_create(env, conf);
    if(!conf_ctx)
    {
        AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Creating Axis2 configuration context failed.");
        return NULL;
    }
    axis2_conf_ctx_set_root_dir(conf_ctx, env, axis2_dep_engine_get_repos_path(dep_engine, env));

    conf_ctx_base = axis2_conf_ctx_get_base(conf_ctx, env);
    property = axutil_property_create_with_args(env, 2, 0, 0, is_server_side);
    axis2_ctx_set_property(conf_ctx_base, env, AXIS2_IS_SVR_SIDE, property);

    axis2_init_modules(env, conf_ctx);
    axis2_init_transports(env, conf_ctx);

    if(!axutil_strcmp(is_server_side, AXIS2_VALUE_TRUE))
    {
        axis2_load_services(env, conf_ctx);
    }

    return conf_ctx;
}

AXIS2_EXTERN axis2_conf_ctx_t *AXIS2_CALL
axis2_build_conf_ctx(
    const axutil_env_t * env,
    const axis2_char_t * repo_name)
{
    axis2_conf_ctx_t *conf_ctx = NULL;
    axis2_dep_engine_t *dep_engine = NULL;

    AXIS2_LOG_TRACE(env->log, AXIS2_LOG_SI, "Entry:axis2_build_conf_ctx");
    dep_engine = axis2_dep_engine_create_with_repos_name(env, repo_name);
    if(!dep_engine)
    {
        AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI,
            "Creating deployment engine failed for repository %s", repo_name);
        return NULL;
    }

    conf_ctx = axis2_build_conf_ctx_with_dep_engine(env, dep_engine, AXIS2_VALUE_TRUE);
    if(!conf_ctx)
    {
        AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI,
            "Loading configuration context failed for repository %s.", repo_name);
        return NULL;
    }

    AXIS2_LOG_TRACE(env->log, AXIS2_LOG_SI, "Exit:axis2_build_conf_ctx");
    return conf_ctx;
}

AXIS2_EXTERN axis2_conf_ctx_t *AXIS2_CALL
axis2_build_conf_ctx_with_file(
    const axutil_env_t * env,
    const axis2_char_t * file)
{
    axis2_conf_ctx_t *conf_ctx = NULL;
    axis2_dep_engine_t *dep_engine = NULL;
	axis2_char_t *repos_path = NULL;
	axis2_char_t *temp_path = NULL;
	axis2_char_t *index = NULL;
	axis2_char_t *xmlfile = NULL;
	
	AXIS2_LOG_TRACE(env->log, AXIS2_LOG_SI, "Entry:axis2_build_conf_ctx_with_file");
	temp_path = axutil_strdup(env, file);
	index = axutil_rindex(temp_path, AXIS2_PATH_SEP_CHAR);
	if(!index)
	{/* searching from windows specific path seperator */
		index = axutil_rindex(temp_path, '\\');
	}

	if(!index)
	{
		/** only the xml file name is provided. Assume the default repo path */
		repos_path = AXIS2_GETENV("AXIS2C_HOME");
		xmlfile = file;
	}else
	{
		xmlfile = index+1;
		temp_path[index-temp_path] = '\0';
		repos_path = temp_path;
	}
	
	dep_engine = axis2_dep_engine_create_with_repos_name_and_svr_xml_file(env, repos_path, xmlfile);
    if(!dep_engine)
    {
        AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI,
            "Creating deployment engine for given Axis2 configuration file"
                "(axis2.xml) failed");
        return NULL;
    }

    conf_ctx = axis2_build_conf_ctx_with_dep_engine(env, dep_engine, AXIS2_VALUE_TRUE);
    if(!conf_ctx)
    {
        AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI,
            "Loading configuration context failed for given Axis2 configuration %s.", file);
        return NULL;
    }
	AXIS2_FREE(env->allocator, temp_path);
    AXIS2_LOG_TRACE(env->log, AXIS2_LOG_SI, "Exit:axis2_build_conf_ctx_with_file");
    return conf_ctx;
}

axis2_conf_ctx_t *AXIS2_CALL
axis2_build_client_conf_ctx(
    const axutil_env_t * env,
    const axis2_char_t * axis2_home)
{
    axis2_conf_ctx_t *conf_ctx = NULL;
    axis2_dep_engine_t *dep_engine = NULL;
    axis2_conf_t *conf = NULL;
    axutil_property_t *property = NULL;
    axis2_ctx_t *conf_ctx_base = NULL;

    axis2_status_t status;
    unsigned int len = 0;

    AXIS2_LOG_TRACE(env->log, AXIS2_LOG_SI, "Entry:axis2_build_client_conf_ctx");
{'fraction_non_alphanumeric': 0.08478418570910409, 'fraction_numerical': 0.020583968081247732, 'mean_word_length': 4.165807962529274, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 44, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 9}, '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': '4417269', 'n_tokens_mistral': 4157, 'n_tokens_neox': 4032, 'n_words': 834}