<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 <axutil_url.h>
#include <axutil_string.h>
#include <axutil_string.h>
#include <axutil_file_handler.h>
#include <axutil_network_handler.h>
#include <axutil_types.h>

struct axutil_url
{
    axis2_char_t *protocol;
    axis2_char_t *server;
    int port;
    axis2_char_t *path;
};

AXIS2_EXTERN axutil_url_t * AXIS2_CALL
axutil_url_create(const axutil_env_t *env,
    const axis2_char_t *protocol,
    const axis2_char_t *server,
    const int port,
    const axis2_char_t *path)
{
    axutil_url_t *url = NULL;
    AXIS2_ENV_CHECK(env, NULL);
    AXIS2_PARAM_CHECK(env->error, protocol, NULL);

    url = (axutil_url_t *)AXIS2_MALLOC(env->allocator,
        sizeof(axutil_url_t));

    if (!url)
    {
        AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE);
        return NULL;
    }
    url->protocol = axutil_strdup(env, protocol);
    url->server = NULL;
    url->path = NULL;
    url->port = port;

    if (server)
    {
        url->server = (axis2_char_t *)axutil_strdup(env, server);
    }
    /** if the path is not starting with / we have to make it so
     */
    if (path)
    {
        if (path[0] == '/')
        {
            url->path = (axis2_char_t *)axutil_strdup(env, path);
        }
        else
        {
            url->path = axutil_stracat(env, "/", path);
        }

    }

    return url;
}

AXIS2_EXTERN axutil_url_t * AXIS2_CALL
axutil_url_parse_string(const axutil_env_t *env, 
    const axis2_char_t *str_url)
{
    /**
     * Only accepted format is : 
     * protocol://server:port/path
      * Added file:///path
     * port is optional and the default port is assumed
     * if path is not present / (root) is assumed
     */
    axis2_char_t *tmp_url_str = NULL;
    axutil_url_t *ret = NULL;
    const axis2_char_t *protocol = NULL;
    axis2_char_t *path = NULL;
    axis2_char_t *port_str = NULL;
    axis2_char_t *server = NULL;
    axis2_char_t *params = NULL;
    int port = -1;

    AXIS2_ENV_CHECK(env, NULL);
    AXIS2_PARAM_CHECK(env->error, str_url, NULL);

    tmp_url_str = axutil_strdup(env, str_url);
    if (!tmp_url_str)
    {
        return NULL;
    }
    protocol = tmp_url_str;
    server = strstr(tmp_url_str, "://");
    if (!server)
    {
        AXIS2_ERROR_SET(env->error, AXIS2_ERROR_INVALID_ADDRESS,
            AXIS2_FAILURE);
        AXIS2_FREE(env->allocator, tmp_url_str);
        return NULL;
    }
    if (axutil_strlen(server) < 3 * sizeof(axis2_char_t))
    {
        AXIS2_ERROR_SET(env->error, AXIS2_ERROR_INVALID_ADDRESS,
            AXIS2_FAILURE);
        AXIS2_FREE(env->allocator, tmp_url_str);
        return NULL;
    }
    *server = '\0';
    server += 3 * sizeof(axis2_char_t); /* skip "://" part */
    if (axutil_strlen(server) <= 0)
    {
        AXIS2_ERROR_SET(env->error, AXIS2_ERROR_INVALID_ADDRESS,
            AXIS2_FAILURE);
        AXIS2_FREE(env->allocator, tmp_url_str);
        return NULL;
    }
    /* if the url is file:// thing we need the protocol and
     * path only
     */
    if (0 == axutil_strcasecmp(protocol, (const axis2_char_t *)"file"))
    {
        ret = axutil_url_create(env, protocol, NULL, 0, server);
        AXIS2_FREE(env->allocator, tmp_url_str);
        return ret;
    }
    port_str = strchr(server, ':');
    if (!port_str)
    {
        if (0 == axutil_strcasecmp(protocol, "http"))
        {
            port = 80;
        }
        if (0 == axutil_strcasecmp(protocol, "ftp"))
        {
            port = 20;
        }
        if (0 == axutil_strcasecmp(protocol, "smtp"))
        {
            port = 25;
        }
        path = strchr(server, '/');
        if (!path)
        {
            /* No path - assume def path ('/') */
            params = strchr(server, '?');<commit_msg>fixed the axutil_url_parse_string to use the default https port when the port is not specified<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 <axutil_url.h>
#include <axutil_string.h>
#include <axutil_string.h>
#include <axutil_file_handler.h>
#include <axutil_network_handler.h>
#include <axutil_types.h>

struct axutil_url
{
    axis2_char_t *protocol;
    axis2_char_t *server;
    int port;
    axis2_char_t *path;
};

AXIS2_EXTERN axutil_url_t * AXIS2_CALL
axutil_url_create(const axutil_env_t *env,
    const axis2_char_t *protocol,
    const axis2_char_t *server,
    const int port,
    const axis2_char_t *path)
{
    axutil_url_t *url = NULL;
    AXIS2_ENV_CHECK(env, NULL);
    AXIS2_PARAM_CHECK(env->error, protocol, NULL);

    url = (axutil_url_t *)AXIS2_MALLOC(env->allocator,
        sizeof(axutil_url_t));

    if (!url)
    {
        AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE);
        return NULL;
    }
    url->protocol = axutil_strdup(env, protocol);
    url->server = NULL;
    url->path = NULL;
    url->port = port;

    if (server)
    {
        url->server = (axis2_char_t *)axutil_strdup(env, server);
    }
    /** if the path is not starting with / we have to make it so
     */
    if (path)
    {
        if (path[0] == '/')
        {
            url->path = (axis2_char_t *)axutil_strdup(env, path);
        }
        else
        {
            url->path = axutil_stracat(env, "/", path);
        }

    }

    return url;
}

AXIS2_EXTERN axutil_url_t * AXIS2_CALL
axutil_url_parse_string(const axutil_env_t *env, 
    const axis2_char_t *str_url)
{
    /**
     * Only accepted format is : 
     * protocol://server:port/path
      * Added file:///path
     * port is optional and the default port is assumed
     * if path is not present / (root) is assumed
     */
    axis2_char_t *tmp_url_str = NULL;
    axutil_url_t *ret = NULL;
    const axis2_char_t *protocol = NULL;
    axis2_char_t *path = NULL;
    axis2_char_t *port_str = NULL;
    axis2_char_t *server = NULL;
    axis2_char_t *params = NULL;
    int port = -1;

    AXIS2_ENV_CHECK(env, NULL);
    AXIS2_PARAM_CHECK(env->error, str_url, NULL);

    tmp_url_str = axutil_strdup(env, str_url);
    if (!tmp_url_str)
    {
        return NULL;
    }
    protocol = tmp_url_str;
    server = strstr(tmp_url_str, "://");
    if (!server)
    {
        AXIS2_ERROR_SET(env->error, AXIS2_ERROR_INVALID_ADDRESS,
            AXIS2_FAILURE);
        AXIS2_FREE(env->allocator, tmp_url_str);
        return NULL;
    }
    if (axutil_strlen(server) < 3 * sizeof(axis2_char_t))
    {
        AXIS2_ERROR_SET(env->error, AXIS2_ERROR_INVALID_ADDRESS,
            AXIS2_FAILURE);
        AXIS2_FREE(env->allocator, tmp_url_str);
        return NULL;
    }
    *server = '\0';
    server += 3 * sizeof(axis2_char_t); /* skip "://" part */
    if (axutil_strlen(server) <= 0)
    {
        AXIS2_ERROR_SET(env->error, AXIS2_ERROR_INVALID_ADDRESS,
            AXIS2_FAILURE);
        AXIS2_FREE(env->allocator, tmp_url_str);
        return NULL;
    }
    /* if the url is file:// thing we need the protocol and
     * path only
     */
    if (0 == axutil_strcasecmp(protocol, (const axis2_char_t *)"file"))
    {
        ret = axutil_url_create(env, protocol, NULL, 0, server);
        AXIS2_FREE(env->allocator, tmp_url_str);
        return ret;
    }
    port_str = strchr(server, ':');
    if (!port_str)
    {
        if (axutil_strcasecmp(protocol, "http") == 0)
            port = 80;
        else if (axutil_strcasecmp(protocol, "https") == 0)
            port = 443;
        else if (axutil_strcasecmp(protocol, "ftp") == 0)
            port = 20;
        else if (axutil_strcasecmp(protocol, "smtp") == 0)
            port = 25;
        
        path = strchr(server, '/');
        if (!path)
        {
            /* No path - assume def path ('/') */
            params = strchr(server, '?');
{'fraction_non_alphanumeric': 0.10968229954614221, 'fraction_numerical': 0.014264102009941647, 'mean_word_length': 2.5419058553386913, 'pattern_counts': {'":': 4, '<': 19, '<?xml version=': 0, '>': 51, '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': '6133714', 'n_tokens_mistral': 3222, 'n_tokens_neox': 3134, 'n_words': 797}