<commit_before>/******************************************************************
 *
 * Copyright 2014 Samsung Electronics All Rights Reserved.
 *
 *
 *
 * Licensed 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 <string.h>

#include "oic_malloc.h"
#include "oic_string.h"
#include "caremotehandler.h"
#include "logger.h"

#define TAG "CA"

CAEndpoint_t *CACloneEndpoint(const CAEndpoint_t *rep)
{
    if (NULL == rep)
    {
        OIC_LOG(ERROR, TAG, "parameter is null");
        return NULL;
    }

    // allocate the remote end point structure.
    CAEndpoint_t *clone = (CAEndpoint_t *)OICMalloc(sizeof (CAEndpoint_t));
    if (NULL == clone)
    {
        OIC_LOG(ERROR, TAG, "CACloneRemoteEndpoint Out of memory");
        return NULL;
    }
    *clone = *rep;

    return clone;
}

CARequestInfo_t *CACloneRequestInfo(const CARequestInfo_t *rep)
{
    if (NULL == rep)
    {
        OIC_LOG(ERROR, TAG, "parameter is null");
        return NULL;
    }

    // allocate the request info structure.
    CARequestInfo_t *clone = (CARequestInfo_t *) OICMalloc(sizeof(CARequestInfo_t));
    if (!clone)
    {
        OIC_LOG(ERROR, TAG, "CACloneRequestInfo Out of memory");
        return NULL;
    }

    *clone = *rep;

    if (rep->info.token)
    {
        char *temp = NULL;

        // allocate token field
        uint8_t len = rep->info.tokenLength;

        if (len)
        {
            temp = (char *) OICCalloc(len, sizeof(char));
            if (!temp)
            {
                OIC_LOG(ERROR, TAG, "CACloneRequestInfo Out of memory");

                CADestroyRequestInfoInternal(clone);

                return NULL;
            }
            memcpy(temp, rep->info.token, len);
        }

        // save the token
        clone->info.token = temp;
        clone->info.tokenLength = len;
    }

    if (NULL != rep->info.options && 0 < rep->info.numOptions)
    {
        // save the options
        clone->info.options =
            (CAHeaderOption_t *) OICMalloc(sizeof(CAHeaderOption_t) * rep->info.numOptions);
        if (NULL == clone->info.options)
        {
            OIC_LOG(ERROR, TAG, "CACloneRequestInfo Out of memory");
            OICFree(clone->info.token);
            OICFree(clone);
            return NULL;
        }
        memcpy(clone->info.options, rep->info.options,
               sizeof(CAHeaderOption_t) * rep->info.numOptions);
    }
    else
    {
        clone->info.options = NULL;
        clone->info.numOptions = 0;
    }

    if (NULL != rep->info.payload)
    {
        // allocate payload field
        char *temp = OICStrdup(rep->info.payload);
        if (NULL == temp)
        {
            OIC_LOG(ERROR, TAG, "CACloneRequestInfo Out of memory");

            CADestroyRequestInfoInternal(clone);

            return NULL;
        }

        // save the payload
        clone->info.payload = temp;
    }

    if (NULL != rep->info.resourceUri)
    {
        // allocate payload field
        char *temp = OICStrdup(rep->info.resourceUri);
        if (NULL == temp)
        {
            OIC_LOG(ERROR, TAG, "CACloneRequestInfo Out of memory");

            CADestroyRequestInfoInternal(clone);

            return NULL;
        }

        // save the resourceUri
        clone->info.resourceUri = temp;
    }

    return clone;
}

CAResponseInfo_t *CACloneResponseInfo(const CAResponseInfo_t *rep)
{
    if (NULL == rep)
    {
        OIC_LOG(ERROR, TAG, "Response pointer is NULL");
        return NULL;
    }

    // check the result value of response info.
    switch (rep->result)
    {
        case CA_EMPTY:
        case CA_SUCCESS:
        case CA_CREATED:
        case CA_DELETED:
        case CA_VALID:
        case CA_CHANGED:
        case CA_CONTENT:
        case CA_BAD_REQ:
        case CA_BAD_OPT:
        case CA_NOT_FOUND:
        case CA_INTERNAL_SERVER_ERROR:
        case CA_RETRANSMIT_TIMEOUT:
            break;

        default:
            OIC_LOG(ERROR, TAG, "Response status code is invalid number");
            return NULL;<commit_msg>Fix failure to respond when SRM says Access Denied.<commit_after>/******************************************************************
 *
 * Copyright 2014 Samsung Electronics All Rights Reserved.
 *
 *
 *
 * Licensed 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 <string.h>

#include "oic_malloc.h"
#include "oic_string.h"
#include "caremotehandler.h"
#include "logger.h"

#define TAG "CA"

CAEndpoint_t *CACloneEndpoint(const CAEndpoint_t *rep)
{
    if (NULL == rep)
    {
        OIC_LOG(ERROR, TAG, "parameter is null");
        return NULL;
    }

    // allocate the remote end point structure.
    CAEndpoint_t *clone = (CAEndpoint_t *)OICMalloc(sizeof (CAEndpoint_t));
    if (NULL == clone)
    {
        OIC_LOG(ERROR, TAG, "CACloneRemoteEndpoint Out of memory");
        return NULL;
    }
    *clone = *rep;

    return clone;
}

CARequestInfo_t *CACloneRequestInfo(const CARequestInfo_t *rep)
{
    if (NULL == rep)
    {
        OIC_LOG(ERROR, TAG, "parameter is null");
        return NULL;
    }

    // allocate the request info structure.
    CARequestInfo_t *clone = (CARequestInfo_t *) OICMalloc(sizeof(CARequestInfo_t));
    if (!clone)
    {
        OIC_LOG(ERROR, TAG, "CACloneRequestInfo Out of memory");
        return NULL;
    }

    *clone = *rep;

    if (rep->info.token)
    {
        char *temp = NULL;

        // allocate token field
        uint8_t len = rep->info.tokenLength;

        if (len)
        {
            temp = (char *) OICCalloc(len, sizeof(char));
            if (!temp)
            {
                OIC_LOG(ERROR, TAG, "CACloneRequestInfo Out of memory");

                CADestroyRequestInfoInternal(clone);

                return NULL;
            }
            memcpy(temp, rep->info.token, len);
        }

        // save the token
        clone->info.token = temp;
        clone->info.tokenLength = len;
    }

    if (NULL != rep->info.options && 0 < rep->info.numOptions)
    {
        // save the options
        clone->info.options =
            (CAHeaderOption_t *) OICMalloc(sizeof(CAHeaderOption_t) * rep->info.numOptions);
        if (NULL == clone->info.options)
        {
            OIC_LOG(ERROR, TAG, "CACloneRequestInfo Out of memory");
            OICFree(clone->info.token);
            OICFree(clone);
            return NULL;
        }
        memcpy(clone->info.options, rep->info.options,
               sizeof(CAHeaderOption_t) * rep->info.numOptions);
    }
    else
    {
        clone->info.options = NULL;
        clone->info.numOptions = 0;
    }

    if (NULL != rep->info.payload)
    {
        // allocate payload field
        char *temp = OICStrdup(rep->info.payload);
        if (NULL == temp)
        {
            OIC_LOG(ERROR, TAG, "CACloneRequestInfo Out of memory");

            CADestroyRequestInfoInternal(clone);

            return NULL;
        }

        // save the payload
        clone->info.payload = temp;
    }

    if (NULL != rep->info.resourceUri)
    {
        // allocate payload field
        char *temp = OICStrdup(rep->info.resourceUri);
        if (NULL == temp)
        {
            OIC_LOG(ERROR, TAG, "CACloneRequestInfo Out of memory");

            CADestroyRequestInfoInternal(clone);

            return NULL;
        }

        // save the resourceUri
        clone->info.resourceUri = temp;
    }

    return clone;
}

CAResponseInfo_t *CACloneResponseInfo(const CAResponseInfo_t *rep)
{
    if (NULL == rep)
    {
        OIC_LOG(ERROR, TAG, "Response pointer is NULL");
        return NULL;
    }

    // check the result value of response info.
    // Keep this check in sync with CAResponseResult_t
    switch (rep->result)
    {
        case CA_EMPTY:
        case CA_SUCCESS:
        case CA_CREATED:
        case CA_DELETED:
        case CA_VALID:
        case CA_CHANGED:
        case CA_CONTENT:
        case CA_BAD_REQ:
        case CA_UNAUTHORIZED_REQ:
        case CA_BAD_OPT:
        case CA_FORBIDDEN_REQ:
        case CA_NOT_FOUND:
        case CA_INTERNAL_SERVER_ERROR:
        case CA_RETRANSMIT_TIMEOUT:
            break;

        default:
            OIC_LOG_V(ERROR, TAG, "Response code  %u is invalid", rep->result);
            return NULL;
{'fraction_non_alphanumeric': 0.12778429073856976, 'fraction_numerical': 0.0023446658851113715, 'mean_word_length': 2.117607973421927, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 52, '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': '6739861', 'n_tokens_mistral': 2836, 'n_tokens_neox': 2739, 'n_words': 738}