replace : iotivity -> iotivity-sec
[platform/upstream/iotivity.git] / service / notification / src / provider / NSProviderSystem.c
1 //******************************************************************\r
2 //\r
3 // Copyright 2016 Samsung Electronics All Rights Reserved.\r
4 //\r
5 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\r
6 //\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
10 //\r
11 //      http://www.apache.org/licenses/LICENSE-2.0\r
12 //\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
18 //\r
19 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\r
20 #include "NSProviderSystem.h"\r
21 \r
22 #if (defined WITH_CLOUD)\r
23 #define MAX_SERVER_ADDRESS 32\r
24 static char NSRemoteServerAddress[MAX_SERVER_ADDRESS] = {0,};\r
25 #endif\r
26 \r
27 #ifdef WITH_MQ\r
28 static NSMQServerInfo * mqServerInfo = NULL;\r
29 #endif\r
30 \r
31 static NSConnectionState NSProviderConnectionState;\r
32 \r
33 NSProviderInfo * providerInfo;\r
34 bool NSPolicy = true;\r
35 bool NSResourceSecurity = false;\r
36 \r
37 void NSSetProviderConnectionState(NSConnectionState state)\r
38 {\r
39     NS_LOG(DEBUG, "NSSetProviderConnectionState");\r
40 \r
41     NSProviderConnectionState = state;\r
42 }\r
43 \r
44 NSConnectionState NSGetProviderConnectionState()\r
45 {\r
46     NS_LOG(DEBUG, "Change Connection State");\r
47 \r
48     return NSProviderConnectionState;\r
49 }\r
50 \r
51 #if (defined WITH_CLOUD)\r
52 void NSSetRemoteServerAddress(char *serverAddress)\r
53 {\r
54 \r
55     OICStrcpy(NSRemoteServerAddress, MAX_SERVER_ADDRESS, serverAddress);\r
56 }\r
57 \r
58 void NSDeleteRemoteServerAddress(char *serverAddress)\r
59 {\r
60     NS_LOG_V(INFO_PRIVATE, "Delete cloud address: %s", serverAddress);\r
61 \r
62     memset(NSRemoteServerAddress, 0, MAX_SERVER_ADDRESS);\r
63 }\r
64 \r
65 bool NSIsRemoteServerAddress(char *serverAddress)\r
66 {\r
67     NS_LOG_V(INFO_PRIVATE, "Check server address: %s", serverAddress);\r
68 \r
69     if (serverAddress != NULL)\r
70     {\r
71         return strstr(NSRemoteServerAddress, serverAddress);\r
72     }\r
73 \r
74     return false;\r
75 }\r
76 #endif\r
77 \r
78 void NSInitProviderInfo(const char * userInfo)\r
79 {\r
80     NS_LOG(DEBUG, "NSInitProviderInfo");\r
81 \r
82     providerInfo = (NSProviderInfo *) OICMalloc(sizeof(NSProviderInfo));\r
83     const char * generatedUuid = (char *)OCGetServerInstanceIDString();\r
84     NS_LOG_V(INFO_PRIVATE, "Generate Provider ID: %s", generatedUuid);\r
85     OICStrcpy(providerInfo->providerId, UUID_STRING_SIZE, generatedUuid);\r
86 \r
87     providerInfo->providerName = NULL;\r
88     providerInfo->userInfo = NULL;\r
89 \r
90     if (userInfo)\r
91     {\r
92         providerInfo->userInfo = OICStrdup(userInfo);\r
93     }\r
94 }\r
95 \r
96 void NSDeinitProviderInfo()\r
97 {\r
98     NS_LOG(DEBUG, "NSDeinitProviderInfo");\r
99 \r
100     if (!providerInfo)\r
101     {\r
102         NS_LOG(DEBUG, "providerInfo is NULL");\r
103         return;\r
104     }\r
105 \r
106     if (providerInfo->providerName)\r
107     {\r
108         NSOICFree(providerInfo->providerName);\r
109         providerInfo->providerName = NULL;\r
110     }\r
111 \r
112     if (providerInfo->userInfo)\r
113     {\r
114         NSOICFree(providerInfo->userInfo);\r
115         providerInfo->userInfo = NULL;\r
116     }\r
117 \r
118     NSOICFree(providerInfo);\r
119     providerInfo = NULL;\r
120 }\r
121 \r
122 NSProviderInfo * NSGetProviderInfo()\r
123 {\r
124     NS_LOG_V(INFO_PRIVATE, "ProviderInfo: %s", providerInfo->providerId);\r
125 \r
126     return providerInfo;\r
127 }\r
128 \r
129 bool NSGetPolicy()\r
130 {\r
131     return NSPolicy;\r
132 }\r
133 \r
134 void NSSetPolicy(bool policy)\r
135 {\r
136     NSPolicy = policy;\r
137 }\r
138 \r
139 bool NSGetResourceSecurity()\r
140 {\r
141     return NSResourceSecurity;\r
142 }\r
143 \r
144 void NSSetResourceSecurity(bool secured)\r
145 {\r
146     NSResourceSecurity = secured;\r
147 }\r
148 \r
149 const char * NSGetUserInfo()\r
150 {\r
151     return providerInfo->userInfo;\r
152 }\r
153 \r
154 #ifdef WITH_MQ\r
155 void NSSetMQServerInfo(const char * serverUri, OCDevAddr * devAddr)\r
156 {\r
157     if (!mqServerInfo)\r
158     {\r
159         NS_LOG(DEBUG, "setMqServer");\r
160         mqServerInfo = (NSMQServerInfo *)OICMalloc(sizeof(NSMQServerInfo));\r
161         mqServerInfo->serverUri = OICStrdup(serverUri);\r
162         mqServerInfo->devAddr = (OCDevAddr *)OICMalloc(sizeof(OCDevAddr));\r
163         memcpy(mqServerInfo->devAddr, devAddr, sizeof(OCDevAddr));\r
164     }\r
165 }\r
166 \r
167 NSMQServerInfo * NSGetMQServerInfo()\r
168 {\r
169     return mqServerInfo;\r
170 }\r
171 #endif\r