1 //******************************************************************
\r
3 // Copyright 2016 Samsung Electronics All Rights Reserved.
\r
5 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
\r
7 // Licensed under the Apache License, Version 2.0 (the "License");
\r
8 // you may not use this file except in compliance with the License.
\r
9 // You may obtain a copy of the License at
\r
11 // http://www.apache.org/licenses/LICENSE-2.0
\r
13 // Unless required by applicable law or agreed to in writing, software
\r
14 // distributed under the License is distributed on an "AS IS" BASIS,
\r
15 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
\r
16 // See the License for the specific language governing permissions and
\r
17 // limitations under the License.
\r
19 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
\r
20 #include "NSProviderSystem.h"
\r
22 #if(defined WITH_CLOUD && defined RD_CLIENT)
\r
23 #define MAX_SERVER_ADDRESS 32
\r
24 static char NSRemoteServerAddress[MAX_SERVER_ADDRESS] = {0,};
\r
27 static NSConnectionState NSProviderConnectionState;
\r
29 NSProviderInfo * providerInfo;
\r
30 bool NSPolicy = true;
\r
31 bool NSResourceSecurity = true;
\r
33 void NSSetProviderConnectionState(NSConnectionState state)
\r
35 NS_LOG(DEBUG, "NSSetProviderConnectionState");
\r
37 NSProviderConnectionState = state;
\r
40 NSConnectionState NSGetProviderConnectionState()
\r
42 NS_LOG(DEBUG, "Change Connection State");
\r
44 return NSProviderConnectionState;
\r
47 #if(defined WITH_CLOUD && defined RD_CLIENT)
\r
48 void NSSetRemoteServerAddress(char *serverAddress)
\r
51 OICStrcpy(NSRemoteServerAddress, MAX_SERVER_ADDRESS, serverAddress);
\r
54 void NSDeleteRemoteServerAddress(char *serverAddress)
\r
56 NS_LOG_V(DEBUG, "Delete cloud address: %s", serverAddress);
\r
58 memset(NSRemoteServerAddress, 0, MAX_SERVER_ADDRESS);
\r
61 bool NSIsRemoteServerAddress(char *serverAddress)
\r
63 NS_LOG_V(DEBUG, "Check server address: %s", serverAddress);
\r
65 if(serverAddress != NULL)
\r
67 return strstr(NSRemoteServerAddress, serverAddress);
\r
74 void NSInitProviderInfo(const char * userInfo)
\r
76 NS_LOG(DEBUG, "NSInitProviderInfo");
\r
78 providerInfo = (NSProviderInfo *) OICMalloc(sizeof(NSProviderInfo));
\r
79 const char * generatedUuid = (char *)OCGetServerInstanceIDString();
\r
80 NS_LOG_V(DEBUG, "Generate Provider ID: %s", generatedUuid);
\r
81 OICStrcpy(providerInfo->providerId, UUID_STRING_SIZE, generatedUuid);
\r
83 providerInfo->providerName = NULL;
\r
84 providerInfo->userInfo = NULL;
\r
87 providerInfo->userInfo = OICStrdup(userInfo);
\r
90 void NSDeinitProviderInfo()
\r
92 NS_LOG(DEBUG, "NSDeinitProviderInfo");
\r
96 NS_LOG(DEBUG, "providerInfo is NULL");
\r
100 if(providerInfo->providerName)
\r
102 OICFree(providerInfo->providerName);
\r
103 providerInfo->providerName = NULL;
\r
106 if(providerInfo->userInfo)
\r
108 OICFree(providerInfo->userInfo);
\r
109 providerInfo->userInfo = NULL;
\r
112 OICFree(providerInfo);
\r
113 providerInfo = NULL;
\r
116 NSProviderInfo * NSGetProviderInfo()
\r
118 NS_LOG_V(DEBUG, "ProviderInfo: %s", providerInfo->providerId);
\r
120 return providerInfo;
\r
128 void NSSetPolicy(bool policy)
\r
133 bool NSGetResourceSecurity()
\r
135 return NSResourceSecurity;
\r
138 void NSSetResourceSecurity(bool secured)
\r
140 NSResourceSecurity = secured;
\r
143 const char * NSGetUserInfo()
\r
145 return providerInfo->userInfo;
\r