<commit_before>//******************************************************************
//
// Copyright 2016 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 <stdio.h>
#include <stdlib.h>
#include <string.h>

#include "ocstack.h"
#include "logger.h"
#include "octhread.h"
#include "cathreadpool.h"
#include "ocpayload.h"
#include "payload_logging.h"
#include "aclresource.h"
#include "acl_logging.h"
#include "crl_logging.h"
#include "crlresource.h"
#include "ocprovisioningmanager.h"
#include "casecurityinterface.h"
#include "mbedtls/ssl_ciphersuites.h"

#include "utils.h"
#include "cloudAuth.h"
#include "cloudCommon.h"
#include "cloudWrapper.h"
#include "cloudDiscovery.h"

#ifdef __unix__
#include <unistd.h> //for unlink
#endif

#define TAG "cloudCommon"

//[IOT-2147] Requests 50-83 are not confirmed to new OCF spec
//disable them for 1.3 rel, later (1.3.1 or after) they should be rewritten and enabled again
#define DISABLE_50_83_REQUESTS_FOR_1_3_REL 1

#define DEFAULT_HOST            "10.113.68.85"//"127.0.0.1"
#define DEFAULT_PORT            OC_MULTICAST_PORT
#define DEFAULT_AUTH_PROVIDER   "github"
#define DEFAULT_DB_FILE         "./cloud.dat"
#define DEFAULT_RESPONSE_WAIT_TIME (10 * 1000000) //10s

#define GITHUB_AUTH_LINK        "https://github.com/login?return_to=%2Flogin%2Foauth%2Fauthorize%3Fclient_id%3Dea9c18f540323b0213d0%26redirect_uri%3Dhttp%253A%252F%252Fwww.example.com%252Foauth_callback%252F"

#define CLIENT_ONLY(mode)       if (OC_SERVER == (mode)) { wrongRequest(); sendDataToServer = false; break; }

static bool fExit = false;

static oc_thread g_requestsThread = NULL;
static OCDevAddr endPoint;
static char token[1024] = "";
static char authProvider[1024] = DEFAULT_AUTH_PROVIDER;
static char *fname = DEFAULT_DB_FILE;
static uint64_t timeout;
static uint16_t g_credId = 0;

static oc_cond cond;
static oc_mutex mutex;

typedef enum {
    SIGN_UP       = 1,
    SIGN_IN       = 2,
    SIGN_OUT      = 3,

    HOST          = 4,
    PORT          = 5,
    DB_FILE       = 6,
    AUTH_PROVIDER = 7,
    USE_RSA = 8,
    SAVE_TRUST_CERT = 9,
    USE_SECURE_CONN = 10,
    CONFIG_SELF_OWNERSHIP = 11,

    DISCOVERY     = 13,
    GET           = 14,
    PUT           = 15,
    POST          = 16,

    CSR_SIGN      = 19,

    CRL_GET       = 20,
    CRL_POST      = 21,

    ACL_ID_CREATE = 30,
    ACL_ID_GET_BY_DEVICE = 31,
    ACL_ID_DELETE = 32,

    ACL_INDIVIDUAL_GET_INFO = 40,
    ACL_INDIVIDUAL_UPDATE_ACE = 41,
    ACL_INDIVIDUAL_UPDATE = 42,
    ACL_INDIVIDUAL_DELETE = 43,
    ACL_INDIVIDUAL_DELETE_ACE = 44,

#ifndef DISABLE_50_83_REQUESTS_FOR_1_3_REL
    ACL_GROUP_CREATE = 50,
    ACL_GROUP_FIND   = 51,
    ACL_GROUP_JOIN   = 52,
    ACL_GROUP_OBSERVE= 53,
    ACL_GROUP_DELETE = 54,

    ACL_GROUP_SHARE_DEVICE  = 60,
    ACL_GROUP_DELETE_DEVICE  = 61,
    ACL_GROUP_GET_INFO  = 62,

    ACL_POLICY_CHECK_REQUEST = 70,

    ACL_GROUP_INVITE_USER = 80,
    ACL_GROUP_GET_INVITE  = 81,
    ACL_GROUP_DELETE_INVITE  = 82,
    ACL_GROUP_CANCEL_INVITE  = 83,
#endif

    EXIT          = 99
}CloudRequest;

static void printMenu(OCMode mode)
{
    char *title = "Client";
    if (OC_SERVER == mode)
    {
        title = "Server";
    }
    printf("************************************************************\n");
    printf("****************** Cloud %s Requests *******************\n", title);
    printf("************************************************************\n");
    printf("** AUTHORIZATION\n");
    printf("** %d - Sign Up request\n", SIGN_UP);
    printf("** %d - Sign In request\n", SIGN_IN);
    printf("** %d - Sign Out request\n", SIGN_OUT);

    printf("** SETTINGS \n");
    printf("** %d - Change default host\n", HOST);
    printf("** %d - Change default port\n", PORT);
    printf("** %d - Change default database filename\n", DB_FILE);
    printf("** %d - Change default auth provider\n", AUTH_PROVIDER);
    printf("** %d - Change TLS cipher suite (ECDSA/RSA)\n", USE_RSA);
    printf("** %d - Save Trust Cert. Chain into Cred of SVR\n", SAVE_TRUST_CERT);
    printf("** %d - Change Protocol type (CoAP/CoAPs)\n", USE_SECURE_CONN);
    printf("** %d - Configure SVRdb as Self-OwnerShip\n", CONFIG_SELF_OWNERSHIP);

    if (OC_CLIENT == mode)
    {
        printf("** DISCOVERY\n");<commit_msg>[IOT-2134] Delete "Change default database" menu item<commit_after>//******************************************************************
//
// Copyright 2016 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 <stdio.h>
#include <stdlib.h>
#include <string.h>

#include "ocstack.h"
#include "logger.h"
#include "octhread.h"
#include "cathreadpool.h"
#include "ocpayload.h"
#include "payload_logging.h"
#include "aclresource.h"
#include "acl_logging.h"
#include "crl_logging.h"
#include "crlresource.h"
#include "ocprovisioningmanager.h"
#include "casecurityinterface.h"
#include "mbedtls/ssl_ciphersuites.h"

#include "utils.h"
#include "cloudAuth.h"
#include "cloudCommon.h"
#include "cloudWrapper.h"
#include "cloudDiscovery.h"

#ifdef __unix__
#include <unistd.h> //for unlink
#endif

#define TAG "cloudCommon"

//[IOT-2147] Requests 50-83 are not confirmed to new OCF spec
//disable them for 1.3 rel, later (1.3.1 or after) they should be rewritten and enabled again
#define DISABLE_50_83_REQUESTS_FOR_1_3_REL 1

#define DEFAULT_HOST            "10.113.68.85"//"127.0.0.1"
#define DEFAULT_PORT            OC_MULTICAST_PORT
#define DEFAULT_AUTH_PROVIDER   "github"
#define DEFAULT_DB_FILE         "./cloud.dat"
#define DEFAULT_RESPONSE_WAIT_TIME (10 * 1000000) //10s

#define GITHUB_AUTH_LINK        "https://github.com/login?return_to=%2Flogin%2Foauth%2Fauthorize%3Fclient_id%3Dea9c18f540323b0213d0%26redirect_uri%3Dhttp%253A%252F%252Fwww.example.com%252Foauth_callback%252F"

#define CLIENT_ONLY(mode)       if (OC_SERVER == (mode)) { wrongRequest(); sendDataToServer = false; break; }

static bool fExit = false;

static oc_thread g_requestsThread = NULL;
static OCDevAddr endPoint;
static char token[1024] = "";
static char authProvider[1024] = DEFAULT_AUTH_PROVIDER;
static char *fname = DEFAULT_DB_FILE;
static uint64_t timeout;
static uint16_t g_credId = 0;

static oc_cond cond;
static oc_mutex mutex;

typedef enum {
    SIGN_UP       = 1,
    SIGN_IN       = 2,
    SIGN_OUT      = 3,

    HOST          = 4,
    PORT          = 5,
    AUTH_PROVIDER = 7,
    USE_RSA = 8,
    SAVE_TRUST_CERT = 9,
    USE_SECURE_CONN = 10,
    CONFIG_SELF_OWNERSHIP = 11,

    DISCOVERY     = 13,
    GET           = 14,
    PUT           = 15,
    POST          = 16,

    CSR_SIGN      = 19,

    CRL_GET       = 20,
    CRL_POST      = 21,

    ACL_ID_CREATE = 30,
    ACL_ID_GET_BY_DEVICE = 31,
    ACL_ID_DELETE = 32,

    ACL_INDIVIDUAL_GET_INFO = 40,
    ACL_INDIVIDUAL_UPDATE_ACE = 41,
    ACL_INDIVIDUAL_UPDATE = 42,
    ACL_INDIVIDUAL_DELETE = 43,
    ACL_INDIVIDUAL_DELETE_ACE = 44,

#ifndef DISABLE_50_83_REQUESTS_FOR_1_3_REL
    ACL_GROUP_CREATE = 50,
    ACL_GROUP_FIND   = 51,
    ACL_GROUP_JOIN   = 52,
    ACL_GROUP_OBSERVE= 53,
    ACL_GROUP_DELETE = 54,

    ACL_GROUP_SHARE_DEVICE  = 60,
    ACL_GROUP_DELETE_DEVICE  = 61,
    ACL_GROUP_GET_INFO  = 62,

    ACL_POLICY_CHECK_REQUEST = 70,

    ACL_GROUP_INVITE_USER = 80,
    ACL_GROUP_GET_INVITE  = 81,
    ACL_GROUP_DELETE_INVITE  = 82,
    ACL_GROUP_CANCEL_INVITE  = 83,
#endif

    EXIT          = 99
}CloudRequest;

static void printMenu(OCMode mode)
{
    char *title = "Client";
    if (OC_SERVER == mode)
    {
        title = "Server";
    }
    printf("************************************************************\n");
    printf("****************** Cloud %s Requests *******************\n", title);
    printf("************************************************************\n");
    printf("** AUTHORIZATION\n");
    printf("** %d - Sign Up request\n", SIGN_UP);
    printf("** %d - Sign In request\n", SIGN_IN);
    printf("** %d - Sign Out request\n", SIGN_OUT);

    printf("** SETTINGS \n");
    printf("** %d - Change default host\n", HOST);
    printf("** %d - Change default port\n", PORT);
    printf("** %d - Change default auth provider\n", AUTH_PROVIDER);
    printf("** %d - Change TLS cipher suite (ECDSA/RSA)\n", USE_RSA);
    printf("** %d - Save Trust Cert. Chain into Cred of SVR\n", SAVE_TRUST_CERT);
    printf("** %d - Change Protocol type (CoAP/CoAPs)\n", USE_SECURE_CONN);
    printf("** %d - Configure SVRdb as Self-OwnerShip\n", CONFIG_SELF_OWNERSHIP);

    if (OC_CLIENT == mode)
    {
        printf("** DISCOVERY\n");
{'fraction_non_alphanumeric': 0.18157894736842106, 'fraction_numerical': 0.03694331983805668, 'mean_word_length': 3.290490664350847, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 2, 'lorem ipsum': 0, 'www.': 4, 'xml': 0}, 'pii_count': 4, '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': '6613485', 'n_tokens_mistral': 3826, 'n_tokens_neox': 3429, 'n_words': 844}