resourcehandler.c 53.9 KB
Newer Older
1 2
//******************************************************************
//
3
// Copyright 2015 Samsung Electronics All Rights Reserved.
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
//
//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//      http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

21
#include "resourcehandler.h"
22

23 24
#include "ocpayload.h"
#include "oic_string.h"
25
#include "oic_malloc.h"
26
#include "cautilinterface.h"
27

28 29 30 31 32 33 34 35 36 37
/**
 * @var ES_RH_TAG
 * @brief Logging tag for module name.
 */
#define ES_RH_TAG "ES_RH"
//-----------------------------------------------------------------------------
// Private variables
//-----------------------------------------------------------------------------

/**
38 39
 * @var g_ESProvResource
 * @brief Structure for holding the Provisioning status
40
 */
41 42 43 44
ProvResource g_ESProvResource;
WiFiResource g_ESWiFiResource;
CloudResource g_ESCloudResource;
DevConfResource g_ESDevConfResource;
45 46 47 48

//-----------------------------------------------------------------------------
// Private internal function prototypes
//-----------------------------------------------------------------------------
49 50 51 52 53
OCEntityHandlerResult OCEntityHandlerCb(OCEntityHandlerFlag flag, OCEntityHandlerRequest *ehRequest,
        void *callback);
OCEntityHandlerResult ProcessGetRequest(OCEntityHandlerRequest *ehRequest, OCRepPayload** payload);
OCEntityHandlerResult ProcessPutRequest(OCEntityHandlerRequest *ehRequest, OCRepPayload** payload);
OCEntityHandlerResult ProcessPostRequest(OCEntityHandlerRequest *ehRequest, OCRepPayload** payload);
54
void updateProvResource(OCEntityHandlerRequest* ehRequest, OCRepPayload* input);
55 56 57
void updateWiFiResource(OCRepPayload* input);
void updateCloudResource(OCRepPayload* input);
void updateDevConfResource(OCRepPayload* input);
Jihun Ha's avatar
Jihun Ha committed
58
const char *getResult(OCStackResult result);
59

60 61 62
ESWiFiCB gWifiRsrcEvtCb = NULL;
ESCloudCB gCloudRsrcEvtCb = NULL;
ESDevConfCB gDevConfRsrcEvtCb = NULL;
63

64 65 66
ESReadUserdataCb gReadUserdataCb = NULL;
ESWriteUserdataCb gWriteUserdataCb = NULL;

67 68 69 70 71
bool CompareResourceInterface(char *from, char *iface)
{
    char *str = OICStrdup(from);
    char *ptr = strtok(str, ";");

72
    if(ptr == NULL)
73
    {
74
        return false;
75
    }
76

77 78 79 80 81 82 83 84 85 86 87 88 89 90
    do
    {
        if(strstr(ptr, ".if."))
        {
            char *if_ptr = NULL;
            if_ptr = strtok(ptr, "=");
            if_ptr = strtok(NULL, "=");

            if(!strcmp(if_ptr, iface))
            {
                return true;
            }
        }

Parkhi's avatar
Parkhi committed
91
    } while ((ptr = strtok(NULL, ";")));
92 93 94 95

    return false;
}

96 97 98 99 100 101 102 103 104 105 106 107
ESResult SetCallbackForUserData(ESReadUserdataCb readCb, ESWriteUserdataCb writeCb)
{
    if(!readCb && !writeCb)
    {
        OIC_LOG(INFO, ES_RH_TAG, "Both of callbacks for user data are null");
        return ES_ERROR;
    }
    gReadUserdataCb = readCb;
    gWriteUserdataCb = writeCb;
    return ES_OK;
}

108
void RegisterWifiRsrcEventCallBack(ESWiFiCB cb)
109
{
110 111 112 113 114 115 116 117 118 119 120
    gWifiRsrcEvtCb = cb;
}

void RegisterCloudRsrcEventCallBack(ESCloudCB cb)
{
    gCloudRsrcEvtCb = cb;
}

void RegisterDevConfRsrcEventCallBack(ESDevConfCB cb)
{
    gDevConfRsrcEvtCb = cb;
121 122
}

123 124
void UnRegisterResourceEventCallBack()
{
125
    if (gWifiRsrcEvtCb)
126
    {
127 128 129 130 131 132 133 134 135
        gWifiRsrcEvtCb = NULL;
    }
    if (gCloudRsrcEvtCb)
    {
        gCloudRsrcEvtCb = NULL;
    }
    if (gDevConfRsrcEvtCb)
    {
        gDevConfRsrcEvtCb = NULL;
136 137 138
    }
}

139
OCStackResult initProvResource(bool isSecured)
140
{
141 142
    g_ESProvResource.status = ES_STATE_INIT;
    g_ESProvResource.lastErrCode = ES_ERRCODE_NO_ERROR;
143

144 145 146
    OCStackResult res = OC_STACK_ERROR;
    if (isSecured)
    {
147
        res = OCCreateResource(&g_ESProvResource.handle, OC_RSRVD_ES_RES_TYPE_PROV,
148 149 150
        OC_RSRVD_INTERFACE_DEFAULT,
        OC_RSRVD_ES_URI_PROV, OCEntityHandlerCb,
        NULL, OC_DISCOVERABLE | OC_OBSERVABLE | OC_SECURE);
151
    }else
152
    {
153
        res = OCCreateResource(&g_ESProvResource.handle, OC_RSRVD_ES_RES_TYPE_PROV,
154 155 156
        OC_RSRVD_INTERFACE_DEFAULT,
        OC_RSRVD_ES_URI_PROV, OCEntityHandlerCb,
        NULL, OC_DISCOVERABLE | OC_OBSERVABLE);
157
    }
158 159 160 161 162 163
    if(res)
    {
        OIC_LOG_V(INFO, ES_RH_TAG, "Created Prov resource with result: %s", getResult(res));
        return res;
    }

164
    res = OCBindResourceTypeToResource(g_ESProvResource.handle, OC_RSRVD_ES_RES_TYPE_COL);
165 166 167 168 169 170
    if(res)
    {
        OIC_LOG_V(INFO, ES_RH_TAG, "Binding Resource type with result: %s", getResult(res));
        return res;
    }

171
    res = OCBindResourceInterfaceToResource(g_ESProvResource.handle, OC_RSRVD_INTERFACE_LL);
172 173
    if(res)
    {
Jihun Ha's avatar
Jihun Ha committed
174
        OIC_LOG_V(INFO, ES_RH_TAG, "Binding Resource interface with result: %s", getResult(res));
175 176
        return res;
    }
177
    res = OCBindResourceInterfaceToResource(g_ESProvResource.handle, OC_RSRVD_INTERFACE_BATCH);
178 179
    if(res)
    {
Jihun Ha's avatar
Jihun Ha committed
180
        OIC_LOG_V(INFO, ES_RH_TAG, "Binding Resource interface with result: %s", getResult(res));
181 182
        return res;
    }
183

184
    OIC_LOG_V(INFO, ES_RH_TAG, "Created Prov resource with result: %s", getResult(res));
185 186
    return res;
}
187

188 189 190 191
OCStackResult initWiFiResource(bool isSecured)
{
    OCStackResult res = OC_STACK_ERROR;

192 193 194 195 196 197 198 199 200 201
    g_ESWiFiResource.supportedFreq = WIFI_BOTH;
    g_ESWiFiResource.supportedMode[0] = WIFI_11A;
    g_ESWiFiResource.supportedMode[1] = WIFI_11B;
    g_ESWiFiResource.supportedMode[2] = WIFI_11G;
    g_ESWiFiResource.supportedMode[3] = WIFI_11N;
    g_ESWiFiResource.numMode = 4;
    g_ESWiFiResource.authType = NONE_AUTH;
    g_ESWiFiResource.encType = NONE_ENC;
    OICStrcpy(g_ESWiFiResource.ssid, sizeof(g_ESWiFiResource.ssid), "");
    OICStrcpy(g_ESWiFiResource.cred, sizeof(g_ESWiFiResource.cred), "");
202 203 204

    if (isSecured)
    {
205
        res = OCCreateResource(&g_ESWiFiResource.handle, OC_RSRVD_ES_RES_TYPE_WIFI,
206 207 208 209 210
        OC_RSRVD_INTERFACE_DEFAULT,
        OC_RSRVD_ES_URI_WIFI, OCEntityHandlerCb,
        NULL, OC_DISCOVERABLE | OC_OBSERVABLE | OC_SECURE);
    }else
    {
211
        res = OCCreateResource(&g_ESWiFiResource.handle, OC_RSRVD_ES_RES_TYPE_WIFI,
212 213 214 215 216 217 218 219 220 221 222 223 224 225
        OC_RSRVD_INTERFACE_DEFAULT,
        OC_RSRVD_ES_URI_WIFI, OCEntityHandlerCb,
        NULL, OC_DISCOVERABLE | OC_OBSERVABLE);
    }

    OIC_LOG_V(INFO, ES_RH_TAG, "Created WiFi resource with result: %s", getResult(res));
    return res;

}

OCStackResult initCloudServerResource(bool isSecured)
{
    OCStackResult res = OC_STACK_ERROR;

226 227 228 229 230
    OICStrcpy(g_ESCloudResource.authCode, sizeof(g_ESCloudResource.authCode), "");
    OICStrcpy(g_ESCloudResource.accessToken, sizeof(g_ESCloudResource.accessToken), "");
    g_ESCloudResource.accessTokenType = NONE_OAUTH_TOKENTYPE;
    OICStrcpy(g_ESCloudResource.authProvider, sizeof(g_ESCloudResource.authProvider), "");
    OICStrcpy(g_ESCloudResource.ciServer, sizeof(g_ESCloudResource.ciServer), "");
231 232 233

    if (isSecured)
    {
234
        res = OCCreateResource(&g_ESCloudResource.handle, OC_RSRVD_ES_RES_TYPE_CLOUDSERVER,
235 236 237 238 239
        OC_RSRVD_INTERFACE_DEFAULT,
        OC_RSRVD_ES_URI_CLOUDSERVER, OCEntityHandlerCb,
        NULL, OC_DISCOVERABLE | OC_OBSERVABLE | OC_SECURE);
    }else
    {
240
        res = OCCreateResource(&g_ESCloudResource.handle, OC_RSRVD_ES_RES_TYPE_CLOUDSERVER,
241 242 243 244 245 246 247 248 249 250 251 252 253 254
        OC_RSRVD_INTERFACE_DEFAULT,
        OC_RSRVD_ES_URI_CLOUDSERVER, OCEntityHandlerCb,
        NULL, OC_DISCOVERABLE | OC_OBSERVABLE);
    }

    OIC_LOG_V(INFO, ES_RH_TAG, "Created CloudServer resource with result: %s", getResult(res));
    return res;

}

OCStackResult initDevConfResource(bool isSecured)
{
    OCStackResult res = OC_STACK_ERROR;

255 256 257 258 259
    OICStrcpy(g_ESDevConfResource.devName, sizeof(g_ESDevConfResource.devName), "");
    OICStrcpy(g_ESDevConfResource.modelNumber, sizeof(g_ESDevConfResource.modelNumber), "");
    OICStrcpy(g_ESDevConfResource.location, sizeof(g_ESDevConfResource.location), "");
    OICStrcpy(g_ESDevConfResource.country, sizeof(g_ESDevConfResource.country), "");
    OICStrcpy(g_ESDevConfResource.language, sizeof(g_ESDevConfResource.language), "");
260 261 262

    if (isSecured)
    {
263
        res = OCCreateResource(&g_ESDevConfResource.handle, OC_RSRVD_ES_RES_TYPE_DEVCONF,
264 265 266 267 268
        OC_RSRVD_INTERFACE_DEFAULT,
        OC_RSRVD_ES_URI_DEVCONF, OCEntityHandlerCb,
        NULL, OC_DISCOVERABLE | OC_OBSERVABLE | OC_SECURE);
    }else
    {
269
        res = OCCreateResource(&g_ESDevConfResource.handle, OC_RSRVD_ES_RES_TYPE_DEVCONF,
270 271 272 273 274 275 276 277 278 279
        OC_RSRVD_INTERFACE_DEFAULT,
        OC_RSRVD_ES_URI_DEVCONF, OCEntityHandlerCb,
        NULL, OC_DISCOVERABLE | OC_OBSERVABLE);
    }

    OIC_LOG_V(INFO, ES_RH_TAG, "Created DevConf resource with result: %s", getResult(res));
    return res;

}

280
void updateProvResource(OCEntityHandlerRequest* ehRequest, OCRepPayload* input)
281
{
282
    OIC_LOG_V(INFO, ES_RH_TAG, "g_ESProvResource.status %d", g_ESProvResource.status);
283 284 285

    if(ehRequest->query)
    {
286
        if(CompareResourceInterface(ehRequest->query, OC_RSRVD_INTERFACE_BATCH))
287
        {
288
            // When Provisioning resource has a POST with BatchInterface
289 290 291
            updateCloudResource(input);
            updateWiFiResource(input);
            updateDevConfResource(input);
292 293
        }
    }
294 295
}

296
void updateWiFiResource(OCRepPayload* input)
297
{
298
    ESWiFiProvData* wiFiData = (ESWiFiProvData*)OICMalloc(sizeof(ESWiFiProvData));
299

300 301 302
    if(wiFiData == NULL)
    {
        OIC_LOG(DEBUG, ES_RH_TAG, "OICMalloc is failed");
303
        return ;
304
    }
305

306 307
    memset(wiFiData->ssid, 0, OIC_STRING_MAX_VALUE);
    memset(wiFiData->pwd, 0, OIC_STRING_MAX_VALUE);
308 309
    wiFiData->authtype = NONE_AUTH;
    wiFiData->enctype = NONE_AUTH;
310 311
    wiFiData->userdata = NULL;

312
    char* ssid = NULL;
313 314
    if (OCRepPayloadGetPropString(input, OC_RSRVD_ES_SSID, &ssid))
    {
315
        OICStrcpy(g_ESWiFiResource.ssid, sizeof(g_ESWiFiResource.ssid), ssid);
316
        OICStrcpy(wiFiData->ssid, sizeof(wiFiData->ssid), ssid);
317
        OIC_LOG_V(INFO, ES_RH_TAG, "g_ESWiFiResource.ssid : %s", g_ESWiFiResource.ssid);
318 319
    }

320
    char* cred = NULL;
321 322
    if (OCRepPayloadGetPropString(input, OC_RSRVD_ES_CRED, &cred))
    {
323
        OICStrcpy(g_ESWiFiResource.cred, sizeof(g_ESWiFiResource.cred), cred);
324
        OICStrcpy(wiFiData->pwd, sizeof(wiFiData->pwd), cred);
325
        OIC_LOG_V(INFO, ES_RH_TAG, "g_ESWiFiResource.cred %s", g_ESWiFiResource.cred);
326 327
    }

328
    int64_t authType = -1;
329 330
    if (OCRepPayloadGetPropInt(input, OC_RSRVD_ES_AUTHTYPE, &authType))
    {
331 332 333
        g_ESWiFiResource.authType = authType;
        wiFiData->authtype = g_ESWiFiResource.authType;
        OIC_LOG_V(INFO, ES_RH_TAG, "g_ESWiFiResource.authType %u", g_ESWiFiResource.authType);
334 335
    }

336
    int64_t encType = -1;
337 338
    if (OCRepPayloadGetPropInt(input, OC_RSRVD_ES_ENCTYPE, &encType))
    {
339 340 341
        g_ESWiFiResource.encType = encType;
        wiFiData->enctype = g_ESWiFiResource.encType;
        OIC_LOG_V(INFO, ES_RH_TAG, "g_ESWiFiResource.encType %u", g_ESWiFiResource.encType);
342
    }
343

344
    if(gReadUserdataCb)
Jihun Ha's avatar
Jihun Ha committed
345
    {
346
        gReadUserdataCb(input, OC_RSRVD_ES_RES_TYPE_WIFI, &wiFiData->userdata);
Jihun Ha's avatar
Jihun Ha committed
347
    }
348

349 350 351 352 353 354 355
    if(ssid || cred || authType!= -1 || encType != -1)
    {
        OIC_LOG(INFO, ES_RH_TAG, "Send WiFiRsrc Callback To ES");

        // TODO : Need to check appropriateness of gWiFiData
        if(gWifiRsrcEvtCb != NULL)
        {
356
            gWifiRsrcEvtCb(ES_OK, wiFiData);
357 358 359 360 361 362 363
        }
        else
        {
            OIC_LOG(ERROR, ES_RH_TAG, "gWifiRsrcEvtCb is NULL");
        }
    }

364
    if(OC_STACK_NO_OBSERVERS == OCNotifyAllObservers(g_ESWiFiResource.handle, OC_HIGH_QOS))
365 366 367 368
    {
        OIC_LOG(INFO, ES_RH_TAG, "Enrollee doesn't have any observers.");
    }

369
    OICFree(wiFiData);
370
}
371

372
void updateCloudResource(OCRepPayload* input)
373
{
374
    ESCloudProvData* cloudData = (ESCloudProvData*)OICMalloc(sizeof(ESCloudProvData));
375

376 377 378
    if(cloudData == NULL)
    {
        OIC_LOG(DEBUG, ES_RH_TAG, "OICMalloc is failed");
379
        return;
380
    }
381 382

    memset(cloudData->authCode, 0, OIC_STRING_MAX_VALUE);
383
    memset(cloudData->accessToken, 0, OIC_STRING_MAX_VALUE);
384
    g_ESCloudResource.accessTokenType = NONE_OAUTH_TOKENTYPE;
385 386
    memset(cloudData->authProvider, 0, OIC_STRING_MAX_VALUE);
    memset(cloudData->ciServer, 0, OIC_STRING_MAX_VALUE);
387 388
    cloudData->userdata = NULL;

389
    char *authCode = NULL;
390 391
    if (OCRepPayloadGetPropString(input, OC_RSRVD_ES_AUTHCODE, &authCode))
    {
392
        OICStrcpy(g_ESCloudResource.authCode, sizeof(g_ESCloudResource.authCode), authCode);
393
        OICStrcpy(cloudData->authCode, sizeof(cloudData->authCode), authCode);
394
        OIC_LOG_V(INFO, ES_RH_TAG, "g_ESCloudResource.authCode %s", g_ESCloudResource.authCode);
395 396
    }

397 398 399
    char *accessToken = NULL;
    if (OCRepPayloadGetPropString(input, OC_RSRVD_ES_ACCESSTOKEN, &accessToken))
    {
400
        OICStrcpy(g_ESCloudResource.accessToken, sizeof(g_ESCloudResource.accessToken), accessToken);
401
        OICStrcpy(cloudData->accessToken, sizeof(cloudData->accessToken), accessToken);
402
        OIC_LOG_V(INFO, ES_RH_TAG, "g_ESCloudResource.accessToken %s", g_ESCloudResource.accessToken);
403 404 405 406 407
    }

    int64_t accessTokenType = -1;
    if (OCRepPayloadGetPropInt(input, OC_RSRVD_ES_ACCESSTOKEN_TYPE, &accessTokenType))
    {
408 409 410
        g_ESCloudResource.accessTokenType = accessTokenType;
        cloudData->accessTokenType = g_ESCloudResource.accessTokenType;
        OIC_LOG_V(INFO, ES_RH_TAG, "g_ESCloudResource.accessTokenType %d", g_ESCloudResource.accessTokenType);
411 412
    }

413
    char *authProvider = NULL;
414 415
    if (OCRepPayloadGetPropString(input, OC_RSRVD_ES_AUTHPROVIDER, &authProvider))
    {
416
        OICStrcpy(g_ESCloudResource.authProvider, sizeof(g_ESCloudResource.authProvider), authProvider);
417
        OICStrcpy(cloudData->authProvider, sizeof(cloudData->authProvider), authProvider);
418
        OIC_LOG_V(INFO, ES_RH_TAG, "g_ESCloudResource.authServerUrl %s", g_ESCloudResource.authProvider);
419 420
    }

421
    char *ciServer = NULL;
422 423
    if (OCRepPayloadGetPropString(input, OC_RSRVD_ES_CISERVER, &ciServer))
    {
424
        OICStrcpy(g_ESCloudResource.ciServer, sizeof(g_ESCloudResource.ciServer), ciServer);
425
        OICStrcpy(cloudData->ciServer, sizeof(cloudData->ciServer), ciServer);
426
        OIC_LOG_V(INFO, ES_RH_TAG, "g_ESCloudResource.ciServer %s", g_ESCloudResource.ciServer);
427
    }
428

429
    if(gReadUserdataCb)
Jihun Ha's avatar
Jihun Ha committed
430
    {
431
        gReadUserdataCb(input, OC_RSRVD_ES_RES_TYPE_CLOUDSERVER, &cloudData->userdata);
Jihun Ha's avatar
Jihun Ha committed
432
    }
433

434
    if(authCode || accessToken || authProvider || ciServer)
435 436 437 438 439 440
    {
        OIC_LOG(INFO, ES_RH_TAG, "Send CloudRsrc Callback To ES");

        // TODO : Need to check appropriateness of gCloudData
        if(gCloudRsrcEvtCb != NULL)
        {
441
            gCloudRsrcEvtCb(ES_OK, cloudData);
442 443 444 445 446 447
        }
        else
        {
            OIC_LOG(ERROR, ES_RH_TAG, "gCloudRsrcEvtCb is NULL");
        }
    }
448

449
    if(OC_STACK_NO_OBSERVERS == OCNotifyAllObservers(g_ESCloudResource.handle, OC_HIGH_QOS))
450 451 452 453
    {
        OIC_LOG(INFO, ES_RH_TAG, "cloudResource doesn't have any observers.");
    }

454
    OICFree(cloudData);
455 456
}

457
void updateDevConfResource(OCRepPayload* input)
458
{
459
    ESDevConfProvData* devConfData = (ESDevConfProvData*)OICMalloc(sizeof(ESDevConfProvData));
460

461 462 463
    if(devConfData == NULL)
    {
        OIC_LOG(DEBUG, ES_RH_TAG, "OICMalloc is failed");
464
        return;
465
    }
466 467
    memset(devConfData->language, 0, OIC_STRING_MAX_VALUE);
    memset(devConfData->country, 0, OIC_STRING_MAX_VALUE);
468 469
    devConfData->userdata = NULL;

470 471 472
    char *location = NULL;
    if (OCRepPayloadGetPropString(input, OC_RSRVD_ES_LOCATION, &location))
    {
473
        OICStrcpy(g_ESDevConfResource.location, sizeof(g_ESDevConfResource.location), location);
474
        OICStrcpy(devConfData->location, sizeof(devConfData->location), location);
475
        OIC_LOG_V(INFO, ES_RH_TAG, "g_ESDevConfResource.location %s", g_ESDevConfResource.location);
476 477
    }

478
    char *country = NULL;
479
    if (OCRepPayloadGetPropString(input, OC_RSRVD_ES_COUNTRY, &country))
480
    {
481
        OICStrcpy(g_ESDevConfResource.country, sizeof(g_ESDevConfResource.country), country);
482
        OICStrcpy(devConfData->country, sizeof(devConfData->country), country);
483
        OIC_LOG_V(INFO, ES_RH_TAG, "g_ESDevConfResource.country %s", g_ESDevConfResource.country);
484 485
    }

486
    char *language = NULL;
487
    if (OCRepPayloadGetPropString(input, OC_RSRVD_ES_LANGUAGE, &language))
488
    {
489
        OICStrcpy(g_ESDevConfResource.language, sizeof(g_ESDevConfResource.language), language);
490
        OICStrcpy(devConfData->language, sizeof(devConfData->language), language);
491
        OIC_LOG_V(INFO, ES_RH_TAG, "g_ESDevConfResource.language %s", g_ESDevConfResource.language);
492
    }
493

494
    if(gReadUserdataCb)
Jihun Ha's avatar
Jihun Ha committed
495
    {
496
        gReadUserdataCb(input, OC_RSRVD_ES_RES_TYPE_DEVCONF, &devConfData->userdata);
Jihun Ha's avatar
Jihun Ha committed
497
    }
498

499 500 501 502 503 504 505
    if(country || language)
    {
        OIC_LOG(INFO, ES_RH_TAG, "Send DevConfRsrc Callback To ES");

        // TODO : Need to check appropriateness of gDevConfData
        if(gDevConfRsrcEvtCb != NULL)
        {
506
            gDevConfRsrcEvtCb(ES_OK, devConfData);
507 508 509 510 511 512
        }
        else
        {
            OIC_LOG(ERROR, ES_RH_TAG, "gDevConfRsrcEvtCb is NULL");
        }
    }
513

514
    if(OC_STACK_NO_OBSERVERS == OCNotifyAllObservers(g_ESDevConfResource.handle, OC_HIGH_QOS))
515 516 517 518
    {
        OIC_LOG(INFO, ES_RH_TAG, "devConfResource doesn't have any observers.");
    }

519
    OICFree(devConfData);
520 521
}

522
OCRepPayload* constructResponseOfWiFi(char *interface)
523 524 525 526 527 528 529 530
{
    OCRepPayload* payload = OCRepPayloadCreate();
    if (!payload)
    {
        OIC_LOG(ERROR, ES_RH_TAG, "Failed to allocate Payload");
        return NULL;
    }

531
    if(g_ESWiFiResource.handle == NULL)
532 533 534 535 536
    {
        OIC_LOG(ERROR, ES_RH_TAG, "WiFi resource is not created");
        return NULL;
    }

537
    OIC_LOG(INFO, ES_RH_TAG, "constructResponse wifi res");
538
    OCRepPayloadSetUri(payload, OC_RSRVD_ES_URI_WIFI);
539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570

    OCRepPayload* repPayload = NULL;
    OCRepPayload* tempPayload = NULL;
    if(!strcmp(interface, OC_RSRVD_INTERFACE_BATCH))
    {
        repPayload = OCRepPayloadCreate();
        if (!repPayload)
        {
            OIC_LOG(ERROR, ES_RH_TAG, "Failed to allocate Payload");
            return NULL;
        }

        tempPayload = payload;
        payload = repPayload;

        size_t interfacesDimensions[MAX_REP_ARRAY_DEPTH] = {1, 0, 0};
        char **interfaces = (char **)OICMalloc(3 * sizeof(char*));

        interfaces[0] = OICStrdup(OC_RSRVD_INTERFACE_DEFAULT);

        OCRepPayloadSetStringArray(payload, OC_RSRVD_ES_INTERFACE, (char **)interfaces, interfacesDimensions);

        size_t resourceTypesDimensions[MAX_REP_ARRAY_DEPTH] = {1, 0, 0};
        char **resourceTypes = (char **)OICMalloc(2 * sizeof(char*));

        resourceTypes[0] = OICStrdup(OC_RSRVD_ES_RES_TYPE_WIFI);

        OCRepPayloadSetStringArray(payload, OC_RSRVD_ES_RES_TYPE, (char **)resourceTypes, resourceTypesDimensions);
    }
    else
    {
        OCRepPayloadAddInterface(payload, OC_RSRVD_INTERFACE_DEFAULT);
571
        OCRepPayloadAddResourceType(payload, OC_RSRVD_ES_RES_TYPE_WIFI);
572
    }
573

574 575 576
    size_t dimensions[MAX_REP_ARRAY_DEPTH] = {g_ESWiFiResource.numMode, 0, 0};
    int64_t *modes_64 = (int64_t *)OICMalloc(g_ESWiFiResource.numMode * sizeof(int64_t));
    for(int i = 0 ; i < g_ESWiFiResource.numMode ; ++i)
577
    {
578
        modes_64[i] = g_ESWiFiResource.supportedMode[i];
579
    }
580
    OCRepPayloadSetIntArray(payload, OC_RSRVD_ES_SUPPORTEDWIFIMODE, (int64_t *)modes_64, dimensions);
581

582 583 584 585 586
    OCRepPayloadSetPropInt(payload, OC_RSRVD_ES_SUPPORTEDWIFIFREQ, g_ESWiFiResource.supportedFreq);
    OCRepPayloadSetPropString(payload, OC_RSRVD_ES_SSID, g_ESWiFiResource.ssid);
    OCRepPayloadSetPropString(payload, OC_RSRVD_ES_CRED, g_ESWiFiResource.cred);
    OCRepPayloadSetPropInt(payload, OC_RSRVD_ES_AUTHTYPE, (int) g_ESWiFiResource.authType);
    OCRepPayloadSetPropInt(payload, OC_RSRVD_ES_ENCTYPE, (int) g_ESWiFiResource.encType);
587

588
    if(gWriteUserdataCb)
Jihun Ha's avatar
Jihun Ha committed
589
    {
590
        gWriteUserdataCb(payload, OC_RSRVD_ES_RES_TYPE_WIFI);
Jihun Ha's avatar
Jihun Ha committed
591
    }
592

593 594 595 596 597 598
    if(!strcmp(interface, OC_RSRVD_INTERFACE_BATCH))
    {
        payload = tempPayload;
        OCRepPayloadSetPropObject(payload, OC_RSRVD_REPRESENTATION, repPayload);
    }

599 600 601
    return payload;
}

602
OCRepPayload* constructResponseOfCloud(char *interface)
603 604 605 606 607 608 609 610
{
    OCRepPayload* payload = OCRepPayloadCreate();
    if (!payload)
    {
        OIC_LOG(ERROR, ES_RH_TAG, "Failed to allocate Payload");
        return NULL;
    }

611
    if(g_ESCloudResource.handle == NULL)
612 613 614 615 616
    {
        OIC_LOG(ERROR, ES_RH_TAG, "CloudServer resource is not created");
        return NULL;
    }

617 618
    OIC_LOG(INFO, ES_RH_TAG, "constructResponse cloudserver res");
    OCRepPayloadSetUri(payload, OC_RSRVD_ES_URI_CLOUDSERVER);
619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652

    OCRepPayload* repPayload = NULL;
    OCRepPayload* tempPayload = NULL;
    if(!strcmp(interface, OC_RSRVD_INTERFACE_BATCH))
    {
        repPayload = OCRepPayloadCreate();
        if (!repPayload)
        {
            OIC_LOG(ERROR, ES_RH_TAG, "Failed to allocate Payload");
            return NULL;
        }

        tempPayload = payload;
        payload = repPayload;

        size_t interfacesDimensions[MAX_REP_ARRAY_DEPTH] = {1, 0, 0};
        char **interfaces = (char **)OICMalloc(3 * sizeof(char*));

        interfaces[0] = OICStrdup(OC_RSRVD_INTERFACE_DEFAULT);

        OCRepPayloadSetStringArray(payload, OC_RSRVD_ES_INTERFACE, (char **)interfaces, interfacesDimensions);

        size_t resourceTypesDimensions[MAX_REP_ARRAY_DEPTH] = {1, 0, 0};
        char **resourceTypes = (char **)OICMalloc(2 * sizeof(char*));

        resourceTypes[0] = OICStrdup(OC_RSRVD_ES_RES_TYPE_CLOUDSERVER);

        OCRepPayloadSetStringArray(payload, OC_RSRVD_ES_RES_TYPE, (char **)resourceTypes, resourceTypesDimensions);
    }
    else
    {
        OCRepPayloadAddInterface(payload, OC_RSRVD_INTERFACE_DEFAULT);
        OCRepPayloadAddResourceType(payload, OC_RSRVD_ES_RES_TYPE_CLOUDSERVER);
    }
653

654 655 656 657 658
    OCRepPayloadSetPropString(payload, OC_RSRVD_ES_AUTHCODE, g_ESCloudResource.authCode);
    OCRepPayloadSetPropString(payload, OC_RSRVD_ES_ACCESSTOKEN, g_ESCloudResource.accessToken);
    OCRepPayloadSetPropInt(payload, OC_RSRVD_ES_ACCESSTOKEN_TYPE, (int)g_ESCloudResource.accessTokenType);
    OCRepPayloadSetPropString(payload, OC_RSRVD_ES_AUTHPROVIDER, g_ESCloudResource.authProvider);
    OCRepPayloadSetPropString(payload, OC_RSRVD_ES_CISERVER, g_ESCloudResource.ciServer);
659 660

    if(gWriteUserdataCb)
661
    {
662
        gWriteUserdataCb(payload, OC_RSRVD_ES_RES_TYPE_CLOUDSERVER);
663
    }
664

665 666 667 668 669 670
    if(!strcmp(interface, OC_RSRVD_INTERFACE_BATCH))
    {
        payload = tempPayload;
        OCRepPayloadSetPropObject(payload, OC_RSRVD_REPRESENTATION, repPayload);
    }

671 672 673
    return payload;
}

674
OCRepPayload* constructResponseOfDevConf(char *interface)
675 676 677 678 679 680 681 682
{
    OCRepPayload* payload = OCRepPayloadCreate();
    if (!payload)
    {
        OIC_LOG(ERROR, ES_RH_TAG, "Failed to allocate Payload");
        return NULL;
    }

683
    if(g_ESDevConfResource.handle == NULL)
684 685 686 687 688
    {
        OIC_LOG(ERROR, ES_RH_TAG, "DevConf resource is not created");
        return NULL;
    }

689 690
    OIC_LOG(INFO, ES_RH_TAG, "constructResponse devconf res");
    OCRepPayloadSetUri(payload, OC_RSRVD_ES_URI_DEVCONF);
691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724

    OCRepPayload* repPayload = NULL;
    OCRepPayload* tempPayload = NULL;
    if(!strcmp(interface, OC_RSRVD_INTERFACE_BATCH))
    {
        repPayload = OCRepPayloadCreate();
        if (!repPayload)
        {
            OIC_LOG(ERROR, ES_RH_TAG, "Failed to allocate Payload");
            return NULL;
        }

        tempPayload = payload;
        payload = repPayload;

        size_t interfacesDimensions[MAX_REP_ARRAY_DEPTH] = {1, 0, 0};
        char **interfaces = (char **)OICMalloc(3 * sizeof(char*));

        interfaces[0] = OICStrdup(OC_RSRVD_INTERFACE_DEFAULT);

        OCRepPayloadSetStringArray(payload, OC_RSRVD_ES_INTERFACE, (char **)interfaces, interfacesDimensions);

        size_t resourceTypesDimensions[MAX_REP_ARRAY_DEPTH] = {1, 0, 0};
        char **resourceTypes = (char **)OICMalloc(2 * sizeof(char*));

        resourceTypes[0] = OICStrdup(OC_RSRVD_ES_RES_TYPE_DEVCONF);

        OCRepPayloadSetStringArray(payload, OC_RSRVD_ES_RES_TYPE, (char **)resourceTypes, resourceTypesDimensions);
    }
    else
    {
        OCRepPayloadAddInterface(payload, OC_RSRVD_INTERFACE_DEFAULT);
        OCRepPayloadAddResourceType(payload, OC_RSRVD_ES_RES_TYPE_DEVCONF);
    }
725

726 727 728 729 730
    OCRepPayloadSetPropString(payload, OC_RSRVD_ES_DEVNAME, g_ESDevConfResource.devName);
    OCRepPayloadSetPropString(payload, OC_RSRVD_ES_MODELNUMBER, g_ESDevConfResource.modelNumber);
    OCRepPayloadSetPropString(payload, OC_RSRVD_ES_LOCATION, g_ESDevConfResource.location);
    OCRepPayloadSetPropString(payload, OC_RSRVD_ES_LANGUAGE, g_ESDevConfResource.language);
    OCRepPayloadSetPropString(payload, OC_RSRVD_ES_COUNTRY, g_ESDevConfResource.country);
731

732
    if(gWriteUserdataCb)
Jihun Ha's avatar
Jihun Ha committed
733
    {
734
        gWriteUserdataCb(payload, OC_RSRVD_ES_RES_TYPE_DEVCONF);
Jihun Ha's avatar
Jihun Ha committed
735
    }
736

737 738 739 740 741 742
    if(!strcmp(interface, OC_RSRVD_INTERFACE_BATCH))
    {
        payload = tempPayload;
        OCRepPayloadSetPropObject(payload, OC_RSRVD_REPRESENTATION, repPayload);
    }

743 744 745 746 747 748 749 750 751 752 753 754
    return payload;
}

OCRepPayload* constructResponseOfProv(OCEntityHandlerRequest *ehRequest)
{
    OCRepPayload* payload = OCRepPayloadCreate();
    if (!payload)
    {
        OIC_LOG(ERROR, ES_RH_TAG, "Failed to allocate Payload");
        return NULL;
    }

755
    // Requested interface is Link list interface
756 757 758 759 760
    //if(ehRequest->query && CompareResourceInterface(ehRequest->query, OC_RSRVD_INTERFACE_LL))
    if(!ehRequest->query ||
        (ehRequest->query && !strcmp(ehRequest->query, "")) ||
        (ehRequest->query && CompareResourceInterface(ehRequest->query, OC_RSRVD_INTERFACE_LL)) ||
        (ehRequest->query && CompareResourceInterface(ehRequest->query, OC_RSRVD_INTERFACE_DEFAULT)))
761 762 763 764 765
    {
        const OCRepPayload *arrayPayload[3] = {NULL};

        int childResCnt = 0;

766
        if(g_ESWiFiResource.handle != NULL)
767 768 769 770
        {
            OCRepPayload *add = OCRepPayloadCreate();
            if(!add)
            {
771
                OIC_LOG(ERROR, ES_RH_TAG, "Failed to allocate Payload");
772 773 774 775 776 777 778 779 780 781 782
                return NULL;
            }

            size_t dimensions[MAX_REP_ARRAY_DEPTH] = {1, 0, 0};
            char **resourceType = NULL;
            resourceType = (char **)OICMalloc(sizeof(char *) * 1);
            char **resourceInterface = NULL;
            resourceInterface = (char **)OICMalloc(sizeof(char *) * 1);

            if(!resourceType || !resourceInterface)
            {
783
                OIC_LOG(ERROR, ES_RH_TAG, "Failed to allocate Payload");
784 785 786 787 788 789 790 791 792 793 794 795 796
                return NULL;
            }

            resourceType[0] = OICStrdup(OC_RSRVD_ES_RES_TYPE_WIFI);
            resourceInterface[0] = OICStrdup(OC_RSRVD_INTERFACE_DEFAULT);

            add->base.type = PAYLOAD_TYPE_REPRESENTATION;
            OCRepPayloadSetPropString(add, OC_RSRVD_HREF, OC_RSRVD_ES_URI_WIFI);
            OCRepPayloadSetStringArray(add, OC_RSRVD_RESOURCE_TYPE,
                                            (const char **)resourceType, dimensions);
            OCRepPayloadSetStringArray(add, OC_RSRVD_INTERFACE,
                                            (const char **)resourceInterface, dimensions);

797
            OCResourceProperty p = OCGetResourceProperties((OCResourceHandle *)g_ESWiFiResource.handle);
798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816
            OCRepPayload *policy = OCRepPayloadCreate();
            if (!policy)
            {
                OIC_LOG(ERROR, ES_RH_TAG, "Failed to allocate Payload");
                return NULL;
            }

            OCRepPayloadSetPropInt(policy, OC_RSRVD_BITMAP,
                                    ((p & OC_DISCOVERABLE) | (p & OC_OBSERVABLE)));
            if (p & OC_SECURE)
            {
                OCRepPayloadSetPropBool(policy, OC_RSRVD_SECURE, p & OC_SECURE);
                uint16_t securePort = CAGetAssignedPortNumber(ehRequest->devAddr.adapter,
                                                                    ehRequest->devAddr.flags);
                OCRepPayloadSetPropInt(policy, OC_RSRVD_HOSTING_PORT, securePort);
            }

            OCRepPayloadSetPropObject(add, OC_RSRVD_POLICY, policy);

817 818 819
            arrayPayload[childResCnt++] = add;
        }

820
        if(g_ESDevConfResource.handle != NULL)
821 822 823 824
        {
            OCRepPayload *add = OCRepPayloadCreate();
            if(!add)
            {
825
                OIC_LOG(ERROR, ES_RH_TAG, "Failed to allocate Payload");
826 827 828 829 830 831 832 833 834 835 836
                return NULL;
            }

            size_t dimensions[MAX_REP_ARRAY_DEPTH] = {1, 0, 0};
            char **resourceType = NULL;
            resourceType = (char **)OICMalloc(sizeof(char *) * 1);
            char **resourceInterface = NULL;
            resourceInterface = (char **)OICMalloc(sizeof(char *) * 1);

            if(!resourceType || !resourceInterface)
            {
837
                OIC_LOG(ERROR, ES_RH_TAG, "Failed to allocate Payload");
838 839 840 841 842 843 844 845 846 847 848 849 850
                return NULL;
            }

            resourceType[0] = OICStrdup(OC_RSRVD_ES_RES_TYPE_DEVCONF);
            resourceInterface[0] = OICStrdup(OC_RSRVD_INTERFACE_DEFAULT);

            add->base.type = PAYLOAD_TYPE_REPRESENTATION;
            OCRepPayloadSetPropString(add, OC_RSRVD_HREF, OC_RSRVD_ES_URI_DEVCONF);
            OCRepPayloadSetStringArray(add, OC_RSRVD_RESOURCE_TYPE,
                                            (const char **)resourceType, dimensions);
            OCRepPayloadSetStringArray(add, OC_RSRVD_INTERFACE,
                                            (const char **)resourceInterface, dimensions);

851
            OCResourceProperty p = OCGetResourceProperties((OCResourceHandle *)g_ESDevConfResource.handle);
852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870
            OCRepPayload *policy = OCRepPayloadCreate();
            if (!policy)
            {
                OIC_LOG(ERROR, ES_RH_TAG, "Failed to allocate Payload");
                return NULL;
            }

            OCRepPayloadSetPropInt(policy, OC_RSRVD_BITMAP,
                                    ((p & OC_DISCOVERABLE) | (p & OC_OBSERVABLE)));
            if (p & OC_SECURE)
            {
                OCRepPayloadSetPropBool(policy, OC_RSRVD_SECURE, p & OC_SECURE);
                uint16_t securePort = CAGetAssignedPortNumber(ehRequest->devAddr.adapter,
                                                                    ehRequest->devAddr.flags);
                OCRepPayloadSetPropInt(policy, OC_RSRVD_HOSTING_PORT, securePort);
            }

            OCRepPayloadSetPropObject(add, OC_RSRVD_POLICY, policy);

871 872 873
            arrayPayload[childResCnt++] = add;
        }

874
        if(g_ESCloudResource.handle != NULL)
875 876 877 878
        {
            OCRepPayload *add = OCRepPayloadCreate();
            if(!add)
            {
879
                OIC_LOG(ERROR, ES_RH_TAG, "Failed to allocate Payload");
880 881 882 883 884 885 886 887 888 889 890
                return NULL;
            }

            size_t dimensions[MAX_REP_ARRAY_DEPTH] = {1, 0, 0};
            char **resourceType = NULL;
            resourceType = (char **)OICMalloc(sizeof(char *) * 1);
            char **resourceInterface = NULL;
            resourceInterface = (char **)OICMalloc(sizeof(char *) * 1);

            if(!resourceType || !resourceInterface)
            {
891
                OIC_LOG(ERROR, ES_RH_TAG, "Failed to allocate Payload");
892 893 894 895 896 897 898 899 900 901 902 903 904
                return NULL;
            }

            resourceType[0] = OICStrdup(OC_RSRVD_ES_RES_TYPE_CLOUDSERVER);
            resourceInterface[0] = OICStrdup(OC_RSRVD_INTERFACE_DEFAULT);

            add->base.type = PAYLOAD_TYPE_REPRESENTATION;
            OCRepPayloadSetPropString(add, OC_RSRVD_HREF, OC_RSRVD_ES_URI_CLOUDSERVER);
            OCRepPayloadSetStringArray(add, OC_RSRVD_RESOURCE_TYPE,
                                            (const char **)resourceType, dimensions);
            OCRepPayloadSetStringArray(add, OC_RSRVD_INTERFACE,
                                            (const char **)resourceInterface, dimensions);

905
            OCResourceProperty p = OCGetResourceProperties((OCResourceHandle *)g_ESCloudResource.handle);
906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924
            OCRepPayload *policy = OCRepPayloadCreate();
            if (!policy)
            {
                OIC_LOG(ERROR, ES_RH_TAG, "Failed to allocate Payload");
                return NULL;
            }

            OCRepPayloadSetPropInt(policy, OC_RSRVD_BITMAP,
                                    ((p & OC_DISCOVERABLE) | (p & OC_OBSERVABLE)));
            if (p & OC_SECURE)
            {
                OCRepPayloadSetPropBool(policy, OC_RSRVD_SECURE, p & OC_SECURE);
                uint16_t securePort = CAGetAssignedPortNumber(ehRequest->devAddr.adapter,
                                                                    ehRequest->devAddr.flags);
                OCRepPayloadSetPropInt(policy, OC_RSRVD_HOSTING_PORT, securePort);
            }

            OCRepPayloadSetPropObject(add, OC_RSRVD_POLICY, policy);

925 926 927 928 929
            arrayPayload[childResCnt++] = add;
        }

        size_t dimensions[MAX_REP_ARRAY_DEPTH] = {childResCnt, 0, 0};

930 931 932 933 934 935 936 937 938 939
        if(!ehRequest->query ||
            (ehRequest->query && !strcmp(ehRequest->query, "")) ||
            (ehRequest->query && CompareResourceInterface(ehRequest->query, OC_RSRVD_INTERFACE_DEFAULT)))
        {
            OIC_LOG(INFO, ES_RH_TAG, "constructResponse prov res");
            OCRepPayloadSetUri(payload, OC_RSRVD_ES_URI_PROV);
            OCRepPayloadAddInterface(payload, OC_RSRVD_INTERFACE_DEFAULT);
            OCRepPayloadAddInterface(payload, OC_RSRVD_INTERFACE_LL);
            OCRepPayloadAddInterface(payload, OC_RSRVD_INTERFACE_BATCH);
            OCRepPayloadAddResourceType(payload, OC_RSRVD_ES_RES_TYPE_PROV);
940
            OCRepPayloadAddResourceType(payload, OC_RSRVD_ES_RES_TYPE_COL);
941

942 943
            OCRepPayloadSetPropInt(payload, OC_RSRVD_ES_PROVSTATUS, g_ESProvResource.status);
            OCRepPayloadSetPropInt(payload, OC_RSRVD_ES_LAST_ERRORCODE, g_ESProvResource.lastErrCode);
944

945 946 947 948 949
            if(gWriteUserdataCb)
            {
                gWriteUserdataCb(payload, OC_RSRVD_ES_RES_TYPE_PROV);
            }

950 951 952 953
            OCRepPayloadSetPropObjectArray(payload, OC_RSRVD_ES_LINKS, arrayPayload, dimensions);
        }
        else    // link list interface
        {
954
            OCRepPayloadSetPropObjectArray(payload, OC_RSRVD_ES_LINKS, arrayPayload, dimensions);
955 956 957 958
        }
    } else if (
        ehRequest->query && CompareResourceInterface(ehRequest->query, OC_RSRVD_INTERFACE_BATCH))

959 960
    {
        OIC_LOG(INFO, ES_RH_TAG, "constructResponse prov res");
961 962
        OCRepPayloadSetUri(payload, OC_RSRVD_ES_URI_PROV);

963 964 965 966 967 968 969 970 971 972 973
        OCRepPayload* repPayload = NULL;

        repPayload = OCRepPayloadCreate();
        if (!repPayload)
        {
            OIC_LOG(ERROR, ES_RH_TAG, "Failed to allocate Payload");
            return NULL;
        }

        size_t interfacesDimensions[MAX_REP_ARRAY_DEPTH] = {3, 0, 0};
        char **interfaces = (char **)OICMalloc(3 * sizeof(char*));
974 975 976 977 978
        if(!interfaces)
        {
            OIC_LOG(ERROR, ES_RH_TAG, "Failed to allocate Payload");
            return NULL;
        }
979 980 981 982 983 984 985 986 987

        interfaces[0] = OICStrdup(OC_RSRVD_INTERFACE_DEFAULT);
        interfaces[1] = OICStrdup(OC_RSRVD_INTERFACE_LL);
        interfaces[2] = OICStrdup(OC_RSRVD_INTERFACE_BATCH);

        OCRepPayloadSetStringArray(repPayload, OC_RSRVD_ES_INTERFACE, (char **)interfaces, interfacesDimensions);

        size_t resourceTypesDimensions[MAX_REP_ARRAY_DEPTH] = {2, 0, 0};
        char **resourceTypes = (char **)OICMalloc(2 * sizeof(char*));
988 989 990 991 992
        if(!resourceTypes)
        {
            OIC_LOG(ERROR, ES_RH_TAG, "Failed to allocate Payload");
            return NULL;
        }
993 994 995 996 997 998

        resourceTypes[0] = OICStrdup(OC_RSRVD_ES_RES_TYPE_PROV);
        resourceTypes[1] = OICStrdup(OC_RSRVD_ES_RES_TYPE_COL);

        OCRepPayloadSetStringArray(repPayload, OC_RSRVD_ES_RES_TYPE, (char **)resourceTypes, resourceTypesDimensions);

999 1000
        OCRepPayloadSetPropInt(repPayload, OC_RSRVD_ES_PROVSTATUS, g_ESProvResource.status);
        OCRepPayloadSetPropInt(repPayload, OC_RSRVD_ES_LAST_ERRORCODE, g_ESProvResource.lastErrCode);
1001

1002 1003 1004 1005
        if(gWriteUserdataCb)
        {
            gWriteUserdataCb(repPayload, OC_RSRVD_ES_RES_TYPE_PROV);
        }
1006

1007
        OCRepPayloadSetPropObject(payload, OC_RSRVD_REPRESENTATION, repPayload);
Jihun Ha's avatar
Jihun Ha committed
1008
    }
1009

1010 1011
    if(ehRequest->query)
    {
1012
        if(CompareResourceInterface(ehRequest->query, OC_RSRVD_INTERFACE_BATCH))
1013
        {// When Provisioning resource has a GET with BatchInterface
1014 1015
            OCRepPayload* head = payload;
            OCRepPayload* nextPayload = NULL;
1016

1017
            nextPayload = constructResponseOfWiFi(OC_RSRVD_INTERFACE_BATCH);
1018
            if(nextPayload != NULL)
1019
            {
1020 1021
                payload->next = nextPayload;
                payload = payload->next;
1022
            }
1023

1024
            nextPayload = constructResponseOfCloud(OC_RSRVD_INTERFACE_BATCH);
1025
            if(nextPayload != NULL)
1026
            {
1027 1028
                payload->next = nextPayload;
                payload = payload->next;
1029
            }
1030

1031
            nextPayload = constructResponseOfDevConf(OC_RSRVD_INTERFACE_BATCH);
Jihun Ha's avatar