Merge branch 'master' into extended-easysetup
[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
27 /**
28  * @var ESX_ENROLLEE_TAG
29  * @brief Logging tag for module name.
30  */
31 #define ESX_ENROLLEE_TAG "ESX"
32
33 UserProperties g_userProperties;
34
35 void SetUserProperties(const UserProperties *prop)
36 {
37     if(prop != NULL)
38     {
39         strncpy(g_userProperties.userValue_str, prop->userValue_str, MAXLEN_STRING);
40         g_userProperties.userValue_int = prop->userValue_int;
41     }
42 }
43
44 void ReadUserdataCb(OCRepPayload* payload, char* resourceType, void* userdata)
45 {
46     OIC_LOG(DEBUG, ESX_ENROLLEE_TAG, "ReadUserdataCb IN");
47
48     if(payload != NULL)
49     {
50         if(strstr(resourceType, OC_RSRVD_ES_RES_TYPE_WIFI))
51         {
52             int64_t value = -1;
53             if (OCRepPayloadGetPropInt(payload, USERPROPERTY_KEY_INT, &value))
54             {
55                 if(userdata != NULL)
56                     userdata = (void*)OICMalloc(sizeof(UserProperties));
57                 OIC_LOG_V(INFO, ESX_ENROLLEE_TAG, "[User specific property] %s : %ld",
58                                                                             USERPROPERTY_KEY_INT, value);
59                 ((UserProperties*)userdata)->userValue_int = value;
60                 g_userProperties.userValue_int = value;
61             }
62         }
63     }
64
65     OIC_LOG(DEBUG, ESX_ENROLLEE_TAG, "ReadUserdataCb OUT");
66 }
67
68 void WriteUserdataCb(OCRepPayload* payload, char* resourceType)
69 {
70     OIC_LOG(DEBUG, ESX_ENROLLEE_TAG, "WriteUserdataCb IN");
71
72     if(payload != NULL)
73     {
74         if(strstr(resourceType, OC_RSRVD_ES_RES_TYPE_WIFI))
75         {
76             OCRepPayloadSetPropInt(payload, USERPROPERTY_KEY_INT, g_userProperties.userValue_int);
77         }
78
79         if(strstr(resourceType, OC_RSRVD_ES_RES_TYPE_DEVCONF))
80         {
81             OCRepPayloadSetPropString(payload, USERPROPERTY_KEY_STR, g_userProperties.userValue_str);
82         }
83     }
84
85     OIC_LOG(DEBUG, ESX_ENROLLEE_TAG, "WriteUserdataCb OUT");
86 }