replace : iotivity -> iotivity-sec
[platform/upstream/iotivity.git] / service / easy-setup / sampleapp / enrollee / linux / easysetup_x.c
1 //******************************************************************
2 //
3 // Copyright 2015 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
22 #include "easysetup_x.h"
23 #include "string.h"
24 #include "oic_malloc.h"
25 #include "logger.h"
26 #include "ocpayload.h"
27
28 /**
29  * @var ESX_ENROLLEE_TAG
30  * @brief Logging tag for module name.
31  */
32 #define ESX_ENROLLEE_TAG "ESX"
33
34 UserProperties g_userProperties;
35
36 void SetUserProperties(const UserProperties *prop)
37 {
38     if(prop != NULL)
39     {
40         strncpy(g_userProperties.userValue_str, prop->userValue_str, MAXLEN_STRING);
41         g_userProperties.userValue_int = prop->userValue_int;
42     }
43 }
44
45 void ReadUserdataCb(OCRepPayload* payload, char* resourceType, void** userdata)
46 {
47     OIC_LOG(DEBUG, ESX_ENROLLEE_TAG, "ReadUserdataCb IN");
48
49     if(payload != NULL)
50     {
51         if(strstr(resourceType, OC_RSRVD_ES_RES_TYPE_WIFICONF))
52         {
53             int64_t value = -1;
54             if (OCRepPayloadGetPropInt(payload, USERPROPERTY_KEY_INT, &value))
55             {
56                 if(*userdata == NULL)
57                 {
58                     *userdata = (void*)OICMalloc(sizeof(UserProperties));
59                     if( *userdata == NULL )
60                     {
61                         OIC_LOG(ERROR, ESX_ENROLLEE_TAG, "OICMalloc for UserProperties is failed");
62                         return ;
63                     }
64                     memset(*userdata, 0, sizeof(UserProperties));
65                 }
66
67                 ((UserProperties*)(*userdata))->userValue_int = value;
68                 OIC_LOG_V(INFO, ESX_ENROLLEE_TAG, "[User specific property] %s : %ld",
69                                                                             USERPROPERTY_KEY_INT, value);
70                 g_userProperties.userValue_int = value;
71             }
72         }
73     }
74
75     OIC_LOG(DEBUG, ESX_ENROLLEE_TAG, "ReadUserdataCb OUT");
76 }
77
78 void WriteUserdataCb(OCRepPayload* payload, char* resourceType)
79 {
80     OIC_LOG(DEBUG, ESX_ENROLLEE_TAG, "WriteUserdataCb IN");
81
82     if(payload != NULL)
83     {
84         if(strstr(resourceType, OC_RSRVD_ES_RES_TYPE_WIFICONF))
85         {
86             OCRepPayloadSetPropInt(payload, USERPROPERTY_KEY_INT, g_userProperties.userValue_int);
87         }
88
89         if(strstr(resourceType, OC_RSRVD_ES_RES_TYPE_DEVCONF))
90         {
91             OCRepPayloadSetPropString(payload, USERPROPERTY_KEY_STR, g_userProperties.userValue_str);
92         }
93     }
94
95     OIC_LOG(DEBUG, ESX_ENROLLEE_TAG, "WriteUserdataCb OUT");
96 }