Merge test folder of test branch
[iotivity.git] / test / include / CloudCommonUtil.h
1 /******************************************************************
2  *
3  * Copyright 2017 Samsung Electronics All Rights Reserved.
4  *
5  *
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  *
19  ******************************************************************/
20
21 #ifndef __CLOUD_COMMON_UTIL_H__
22 #define __CLOUD_COMMON_UTIL_H__
23
24 #include <stddef.h>
25 #include <malloc.h>
26 #ifdef HAVE_UNISTD_H
27 #include <unistd.h>
28 #endif
29 #include <string>
30 #include <fstream>
31 #ifndef __ANDROID__
32 #include <ifaddrs.h>
33 #include <arpa/inet.h>
34 #endif
35 #include <ctime>
36 #include <iostream>
37 #define BOOST_NO_CXX11_SCOPED_ENUMS
38 #include <boost/filesystem.hpp>
39 #undef BOOST_NO_CXX11_SCOPED_ENUMS
40 #include "boost/assign.hpp"
41 #include "octypes.h"
42 #include <curl/curl.h>
43 #include "logger.h"
44 #include "ocpayload.h"
45 #include "ocstack.h"
46 #include "oic_malloc.h"
47 #include "oic_string.h"
48 #include "OCAccountManager.h"
49 #include "OCApi.h"
50 #include "OCPlatform.h"
51 #include "OCPlatform_impl.h"
52 #include "payload_logging.h"
53 #include "rd_client.h"
54 #include "OCRepresentation.h"
55
56 #ifdef __SECURED__
57 #include "ca_adapter_net_ssl.h"
58 #include "CAManager.h"
59 #include "casecurityinterface.h"
60 #include "cathreadpool.h"
61 #include "casecurityinterface.h"
62 #include "cathreadpool.h"
63 #include "occloudprovisioning.h"
64 #include "ocprovisioningmanager.h"
65 #include "oxmjustworks.h"
66 #include "oxmrandompin.h"
67 #include "pmtypes.h"
68 #include "srmutility.h"
69 #include "ssl_ciphersuites.h"
70 #include "utils.h"
71 #include "utlist.h"
72 #include "auth.h"
73 #endif
74
75 #include "Configuration.h"
76 #include "CommonUtil.h"
77 #include "CommonProperties.h"
78 #include "IotivityTest_Logger.h"
79
80 using namespace std;
81 using namespace OC;
82
83 #define INIT_GET_LOGIN_URL "https://github.com/login"
84 #define LOGIN_URL "https://github.com/session"
85 #define IOTIVITY_CLOUD_URL "https://github.com/login?return_to=%2Flogin%2Foauth%2Fauthorize%3Fclient_id%3Dea9c18f540323b0213d0%26redirect_uri%3Dhttp%253A%252F%252Fwww.example.com%252Foauth_callback%252F"
86 #define PAR_POST_VAL "commit=Sign+in&utf8=%E2%9C%93"//"commit=Sign+in&utf8=✓";//"commit=Sign+in&utf8=%E2%9C%93";
87 #define AUTHENTICITY_TOKEN "&authenticity_token="
88
89 typedef struct Stringstr
90 {
91     char *ptr;
92     size_t len;
93 } Stringstr;
94
95 const std::string CONFIG_PROP_FILE = "config.properties";
96 const std::string CLOUD_PROP_FILE = "cloud.properties";
97 const std::string CLOUD_ACCESSTOKEN_KEY = "accesstoken";
98 const std::string CLOUD_UID_KEY ="uid";
99 const std::string CI_SERVER_ETHERNET_IP_KEY = "ci_server_ethernet_ip";
100 const std::string CI_SERVER_WIFI_IP_KEY = "ci_server_wifi_ip";
101 const std::string GITHUB_USER_KEY = "github_userid";
102 const std::string GITHUB_PASSWORD_KEY = "github_password";
103
104 class CloudCommonUtil
105 {
106     static long s_setUpDynamicMemoryUsage;
107     static long s_tearDownDynamicMemoryUsage;
108     static long s_memoryDiffSum;
109
110 public:
111     static std::string g_uid;
112     static std::string g_accessToken;
113     static std::string g_refreshToken;
114     static std::string g_authCode;
115     static std::string g_authprovider;
116
117     static void init_string(Stringstr *str);
118     static std::string getDefaultIp();
119     static std::string getDefaultHostAddess();
120     static OCDevAddr getDefaultEndPoint();
121 #ifdef __SECURED__
122     static OicCloud_t* getCloudServer();
123 #endif
124     static char* get_authenticity_token(const char* resposeTxt);
125     static void create_file(string filename, string data);
126     static char* get_auth_token_code(const char* responseTxt, char *code);
127     static char const* getgithubcode(const char gitlogin[], const char gitpassword[], char *code);
128     static void printRepresentation(OCRepresentation rep);
129     static OCRepresentation parseOCClientResponse(OCClientResponse* clientResponse);
130     static std::string readfile(std::string filename);
131     static char* getGitLoginAuthCodeMain();
132     static bool signUp(OCAccountManager::Ptr accountMgr);
133     static bool signUp(OCAccountManager::Ptr accountMgr, std::string authCode);
134     static bool signIn(OCAccountManager::Ptr accountMgr);
135     static bool signOut(OCAccountManager::Ptr accountMgr);
136 };
137 #endif