1 //******************************************************************
3 // Copyright 2015 Samsung Electronics All Rights Reserved.
5 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
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
11 // http://www.apache.org/licenses/LICENSE-2.0
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.
19 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
21 #include "resourcehandler.h"
25 #include "ocpayload.h"
26 #include "oic_string.h"
30 * @brief Logging tag for module name.
32 #define ES_RH_TAG "ES_RH"
33 //-----------------------------------------------------------------------------
35 //-----------------------------------------------------------------------------
39 * @brief Structure for holding the Provisioning status and target information required to
40 * connect to the target network
42 static ProvResource gProvResource;
43 static WiFiResource gWiFiResource;
44 static CloudResource gCloudResource;
45 static DevConfResource gDevConfResource;
47 //-----------------------------------------------------------------------------
48 // Private internal function prototypes
49 //-----------------------------------------------------------------------------
50 OCEntityHandlerResult OCEntityHandlerCb(OCEntityHandlerFlag flag, OCEntityHandlerRequest *ehRequest,
52 const char *getResult(OCStackResult result);
53 OCEntityHandlerResult ProcessGetRequest(OCEntityHandlerRequest *ehRequest, OCRepPayload** payload);
54 OCEntityHandlerResult ProcessPutRequest(OCEntityHandlerRequest *ehRequest, OCRepPayload** payload);
55 OCEntityHandlerResult ProcessPostRequest(OCEntityHandlerRequest *ehRequest, OCRepPayload** payload);
56 void updateProvResource(OCEntityHandlerRequest* ehRequest, OCRepPayload* input);
57 void updateWiFiResource(OCEntityHandlerRequest* ehRequest, OCRepPayload* input);
58 void updateCloudResource(OCEntityHandlerRequest* ehRequest, OCRepPayload* input);
59 void updateDevConfResource(OCEntityHandlerRequest* ehRequest, OCRepPayload* input);
61 ESEnrolleeResourceEventCallback gNetworkInfoProvEventCb = NULL;
63 void RegisterResourceEventCallBack(ESEnrolleeResourceEventCallback cb)
65 gNetworkInfoProvEventCb = cb;
68 void UnRegisterResourceEventCallBack()
70 if (gNetworkInfoProvEventCb)
72 gNetworkInfoProvEventCb = NULL;
76 void GetTargetNetworkInfoFromProvResource(char *name, char *pass)
78 if (name != NULL && pass != NULL)
80 OICStrcpy(name, MAXSSIDLEN, gWiFiResource.ssid);
81 OICStrcpy(pass, MAXNETCREDLEN, gWiFiResource.cred);
85 OCStackResult initProvResource(bool isSecured)
87 gProvResource.status = NO_PROVISION;
88 gProvResource.trigger = false;
90 OCStackResult res = OC_STACK_ERROR;
93 res = OCCreateResource(&gProvResource.handle, OC_RSRVD_ES_RES_TYPE_PROV,
94 OC_RSRVD_INTERFACE_DEFAULT,
95 OC_RSRVD_ES_URI_PROV, OCEntityHandlerCb,
96 NULL, OC_DISCOVERABLE | OC_OBSERVABLE | OC_SECURE);
99 res = OCCreateResource(&gProvResource.handle, OC_RSRVD_ES_RES_TYPE_PROV,
100 OC_RSRVD_INTERFACE_DEFAULT,
101 OC_RSRVD_ES_URI_PROV, OCEntityHandlerCb,
102 NULL, OC_DISCOVERABLE | OC_OBSERVABLE);
106 OIC_LOG_V(INFO, ES_RH_TAG, "Created Prov resource with result: %s", getResult(res));
110 res = OCBindResourceInterfaceToResource(gProvResource.handle, OC_RSRVD_INTERFACE_LL);
113 OIC_LOG_V(INFO, ES_RH_TAG, "Created Prov resource with result: %s", getResult(res));
116 res = OCBindResourceInterfaceToResource(gProvResource.handle, OC_RSRVD_INTERFACE_BATCH);
119 OIC_LOG_V(INFO, ES_RH_TAG, "Created Prov resource with result: %s", getResult(res));
123 OIC_LOG_V(INFO, ES_RH_TAG, "Created Prov resource with result: %s", getResult(res));
127 OCStackResult initWiFiResource(bool isSecured)
129 OCStackResult res = OC_STACK_ERROR;
131 gWiFiResource.supportedFreq = WiFi_BOTH;
132 gWiFiResource.supportedMode[0] = WiFi_11A;
133 gWiFiResource.supportedMode[1] = WiFi_11B;
134 gWiFiResource.supportedMode[2] = WiFi_11G;
135 gWiFiResource.supportedMode[3] = WiFi_11N;
136 gWiFiResource.numMode = 4;
137 gWiFiResource.authType = NONE_AUTH;
138 gWiFiResource.encType = NONE_ENC;
139 OICStrcpy(gWiFiResource.ssid, sizeof(gWiFiResource.ssid), "");
140 OICStrcpy(gWiFiResource.cred, sizeof(gWiFiResource.cred), "");
144 res = OCCreateResource(&gWiFiResource.handle, OC_RSRVD_ES_RES_TYPE_WIFI,
145 OC_RSRVD_INTERFACE_DEFAULT,
146 OC_RSRVD_ES_URI_WIFI, OCEntityHandlerCb,
147 NULL, OC_DISCOVERABLE | OC_OBSERVABLE | OC_SECURE);
150 res = OCCreateResource(&gWiFiResource.handle, OC_RSRVD_ES_RES_TYPE_WIFI,
151 OC_RSRVD_INTERFACE_DEFAULT,
152 OC_RSRVD_ES_URI_WIFI, OCEntityHandlerCb,
153 NULL, OC_DISCOVERABLE | OC_OBSERVABLE);
156 OIC_LOG_V(INFO, ES_RH_TAG, "Created WiFi resource with result: %s", getResult(res));
161 OCStackResult initCloudServerResource(bool isSecured)
163 OCStackResult res = OC_STACK_ERROR;
165 OICStrcpy(gCloudResource.authCode, sizeof(gCloudResource.authCode), "");
166 OICStrcpy(gCloudResource.authProvider, sizeof(gCloudResource.authProvider), "");
167 OICStrcpy(gCloudResource.ciServer, sizeof(gCloudResource.ciServer), "");
171 res = OCCreateResource(&gCloudResource.handle, OC_RSRVD_ES_RES_TYPE_CLOUDSERVER,
172 OC_RSRVD_INTERFACE_DEFAULT,
173 OC_RSRVD_ES_URI_CLOUDSERVER, OCEntityHandlerCb,
174 NULL, OC_DISCOVERABLE | OC_OBSERVABLE | OC_SECURE);
177 res = OCCreateResource(&gCloudResource.handle, OC_RSRVD_ES_RES_TYPE_CLOUDSERVER,
178 OC_RSRVD_INTERFACE_DEFAULT,
179 OC_RSRVD_ES_URI_CLOUDSERVER, OCEntityHandlerCb,
180 NULL, OC_DISCOVERABLE | OC_OBSERVABLE);
183 OIC_LOG_V(INFO, ES_RH_TAG, "Created CloudServer resource with result: %s", getResult(res));
188 OCStackResult initDevConfResource(bool isSecured)
190 OCStackResult res = OC_STACK_ERROR;
192 OICStrcpy(gDevConfResource.devName, sizeof(gDevConfResource.devName), "");
193 OICStrcpy(gDevConfResource.country, sizeof(gDevConfResource.country), "");
194 OICStrcpy(gDevConfResource.language, sizeof(gDevConfResource.language), "");
198 res = OCCreateResource(&gDevConfResource.handle, OC_RSRVD_ES_RES_TYPE_DEVCONF,
199 OC_RSRVD_INTERFACE_DEFAULT,
200 OC_RSRVD_ES_URI_DEVCONF, OCEntityHandlerCb,
201 NULL, OC_DISCOVERABLE | OC_OBSERVABLE | OC_SECURE);
204 res = OCCreateResource(&gDevConfResource.handle, OC_RSRVD_ES_RES_TYPE_DEVCONF,
205 OC_RSRVD_INTERFACE_DEFAULT,
206 OC_RSRVD_ES_URI_DEVCONF, OCEntityHandlerCb,
207 NULL, OC_DISCOVERABLE | OC_OBSERVABLE);
210 OIC_LOG_V(INFO, ES_RH_TAG, "Created DevConf resource with result: %s", getResult(res));
215 void updateProvResource(OCEntityHandlerRequest *ehRequest, OCRepPayload* input)
217 OIC_LOG_V(INFO, ES_RH_TAG, "gProvResource.status %lld", gProvResource.status);
219 if (OCRepPayloadGetPropBool(input, OC_RSRVD_ES_TRIGGER, &trigger))
222 gProvResource.trigger = trigger;
227 if(strstr(ehRequest->query, OC_RSRVD_INTERFACE_BATCH))
228 {// When Provisioning resource has a POST with BatchInterface
229 updateCloudResource(ehRequest, input);
230 updateWiFiResource(ehRequest, input);
231 updateDevConfResource(ehRequest, input);
236 void updateWiFiResource(OCEntityHandlerRequest* ehRequest, OCRepPayload* input)
240 if (OCRepPayloadGetPropString(input, OC_RSRVD_ES_SSID, &ssid))
242 OICStrcpy(gWiFiResource.ssid, sizeof(gWiFiResource.ssid), ssid);
243 OIC_LOG(INFO, ES_RH_TAG, "got ssid");
247 if (OCRepPayloadGetPropString(input, OC_RSRVD_ES_CRED, &cred))
249 OICStrcpy(gWiFiResource.cred, sizeof(gWiFiResource.cred), cred);
250 OIC_LOG_V(INFO, ES_RH_TAG, "gWiFiResource.cred %s", gWiFiResource.cred);
254 if (OCRepPayloadGetPropInt(input, OC_RSRVD_ES_AUTHTYPE, &authType))
256 gWiFiResource.authType = authType;
257 OIC_LOG_V(INFO, ES_RH_TAG, "gWiFiResource.authType %u", gWiFiResource.authType);
261 if (OCRepPayloadGetPropInt(input, OC_RSRVD_ES_ENCTYPE, &encType))
263 gWiFiResource.encType = encType;
264 OIC_LOG_V(INFO, ES_RH_TAG, "gWiFiResource.encType %u", gWiFiResource.encType);
267 void updateCloudResource(OCEntityHandlerRequest* ehRequest, OCRepPayload* input)
271 if (OCRepPayloadGetPropString(input, OC_RSRVD_ES_AUTHCODE, &authCode))
273 OICStrcpy(gCloudResource.authCode, sizeof(gCloudResource.authCode), authCode);
274 OIC_LOG_V(INFO, ES_RH_TAG, "gCloudResource.authCode %s", gCloudResource.authCode);
278 if (OCRepPayloadGetPropString(input, OC_RSRVD_ES_AUTHPROVIDER, &authProvider))
280 OICStrcpy(gCloudResource.authProvider, sizeof(gCloudResource.authProvider), authProvider);
281 OIC_LOG_V(INFO, ES_RH_TAG, "gCloudResource.authServerUrl %s", gCloudResource.authProvider);
285 if (OCRepPayloadGetPropString(input, OC_RSRVD_ES_CISERVER, &ciServer))
287 OICStrcpy(gCloudResource.ciServer, sizeof(gCloudResource.ciServer), ciServer);
288 OIC_LOG_V(INFO, ES_RH_TAG, "gCloudResource.ciServer %s", gCloudResource.ciServer);
292 void updateDevConfResource(OCEntityHandlerRequest* ehRequest, OCRepPayload* input)
296 if (OCRepPayloadGetPropString(input, OC_RSRVD_ES_AUTHCODE, &country))
298 OICStrcpy(gDevConfResource.country, sizeof(gDevConfResource.country), country);
299 OIC_LOG_V(INFO, ES_RH_TAG, "gDevConfResource.country %s", gDevConfResource.country);
303 if (OCRepPayloadGetPropString(input, OC_RSRVD_ES_AUTHPROVIDER, &language))
305 OICStrcpy(gDevConfResource.language, sizeof(gDevConfResource.language), language);
306 OIC_LOG_V(INFO, ES_RH_TAG, "gDevConfResource.language %s", gDevConfResource.language);
310 OCRepPayload* constructResponseOfWiFi(OCEntityHandlerRequest *ehRequest)
313 OCRepPayload* payload = OCRepPayloadCreate();
316 OIC_LOG(ERROR, ES_RH_TAG, "Failed to allocate Payload");
320 OIC_LOG(INFO, ES_RH_TAG, "constructResponse wifi res");
321 OCRepPayloadSetUri(payload, OC_RSRVD_ES_URI_WIFI);
323 size_t dimensions[MAX_REP_ARRAY_DEPTH] = {gWiFiResource.numMode, 0, 0};
324 OCRepPayloadSetIntArray(payload, OC_RSRVD_ES_SUPPORTEDWIFIMODE, gWiFiResource.supportedMode, dimensions);
326 OCRepPayloadSetPropInt(payload, OC_RSRVD_ES_SUPPORTEDWIFIFREQ, gWiFiResource.supportedFreq);
327 OCRepPayloadSetPropString(payload, OC_RSRVD_ES_SSID, gWiFiResource.ssid);
328 OCRepPayloadSetPropString(payload, OC_RSRVD_ES_CRED, gWiFiResource.cred);
329 OCRepPayloadSetPropInt(payload, OC_RSRVD_ES_AUTHTYPE, gWiFiResource.authType);
330 OCRepPayloadSetPropInt(payload, OC_RSRVD_ES_ENCTYPE, gWiFiResource.encType);
332 printf("%s\n", gWiFiResource.ssid);
337 OCRepPayload* constructResponseOfCloud(OCEntityHandlerRequest *ehRequest)
340 OCRepPayload* payload = OCRepPayloadCreate();
343 OIC_LOG(ERROR, ES_RH_TAG, "Failed to allocate Payload");
347 OIC_LOG(INFO, ES_RH_TAG, "constructResponse prov res");
348 OCRepPayloadSetUri(payload, OC_RSRVD_ES_URI_CLOUDSERVER);
349 OCRepPayloadSetPropString(payload, OC_RSRVD_ES_AUTHCODE, gCloudResource.authCode);
350 OCRepPayloadSetPropString(payload, OC_RSRVD_ES_AUTHPROVIDER, gCloudResource.authProvider);
351 OCRepPayloadSetPropString(payload, OC_RSRVD_ES_CISERVER, gCloudResource.ciServer);
356 OCRepPayload* constructResponseOfDevConf(OCEntityHandlerRequest *ehRequest)
359 OCRepPayload* payload = OCRepPayloadCreate();
362 OIC_LOG(ERROR, ES_RH_TAG, "Failed to allocate Payload");
366 OIC_LOG(INFO, ES_RH_TAG, "constructResponse prov res");
367 OCRepPayloadSetUri(payload, OC_RSRVD_ES_URI_DEVCONF);
368 OCRepPayloadSetPropString(payload, OC_RSRVD_ES_DEVNAME, gDevConfResource.devName);
369 OCRepPayloadSetPropString(payload, OC_RSRVD_ES_LANGUAGE, gDevConfResource.language);
370 OCRepPayloadSetPropString(payload, OC_RSRVD_ES_COUNTRY, gDevConfResource.country);
375 OCRepPayload* constructResponseOfProv(OCEntityHandlerRequest *ehRequest)
377 OCRepPayload* payload = OCRepPayloadCreate();
380 OIC_LOG(ERROR, ES_RH_TAG, "Failed to allocate Payload");
384 OIC_LOG(INFO, ES_RH_TAG, "constructResponse prov res");
385 OCRepPayloadSetUri(payload, OC_RSRVD_ES_URI_PROV);
386 OCRepPayloadSetPropInt(payload, OC_RSRVD_ES_PROVSTATUS, gProvResource.status);
387 OCRepPayloadSetPropBool(payload, OC_RSRVD_ES_TRIGGER, gProvResource.trigger);
391 if(strstr(ehRequest->query, OC_RSRVD_INTERFACE_BATCH))
392 {// When Provisioning resource has a GET with BatchInterface
393 payload->next = constructResponseOfWiFi(ehRequest);
396 payload->next->next = constructResponseOfCloud(ehRequest);
400 if(payload->next->next)
401 payload->next->next->next = constructResponseOfDevConf(ehRequest);
411 OCStackResult CreateEasySetupResources(bool isSecured)
413 OCStackResult res = OC_STACK_ERROR;
415 res = initProvResource(isSecured);
418 // TODO: destroy logic will be added
422 res = initWiFiResource(isSecured);
425 // TODO: destroy logic will be added
429 res = initCloudServerResource(isSecured);
432 // TODO: destroy logic will be added
436 res = initDevConfResource(isSecured);
439 // TODO: destroy logic will be added
443 OCBindResource(gProvResource.handle, gWiFiResource.handle);
444 OCBindResource(gProvResource.handle, gCloudResource.handle);
445 OCBindResource(gProvResource.handle, gDevConfResource.handle);
447 OIC_LOG_V(INFO, ES_RH_TAG, "Created all resources with result: %s", getResult(res));
451 OCStackResult DeleteProvisioningResource()
453 OCStackResult res = OCDeleteResource(gProvResource.handle);
454 if (res != OC_STACK_OK)
456 OIC_LOG_V(INFO, ES_RH_TAG, "Deleting Prov resource error with result: %s", getResult(res));
462 OCStackResult DeleteEasySetupResources()
464 OCStackResult res = OCDeleteResource(gProvResource.handle);
465 if (res != OC_STACK_OK)
467 OIC_LOG_V(INFO, ES_RH_TAG, "Deleting Prov resource error with result: %s", getResult(res));
469 res = OCDeleteResource(gWiFiResource.handle);
470 if (res != OC_STACK_OK)
472 OIC_LOG_V(INFO, ES_RH_TAG, "Deleting WiFi resource error with result: %s", getResult(res));
474 res = OCDeleteResource(gCloudResource.handle);
475 if (res != OC_STACK_OK)
477 OIC_LOG_V(INFO, ES_RH_TAG, "Deleting CloudServer resource error with result: %s", getResult(res));
479 res = OCDeleteResource(gDevConfResource.handle);
480 if (res != OC_STACK_OK)
482 OIC_LOG_V(INFO, ES_RH_TAG, "Deleting DevConf resource error with result: %s", getResult(res));
488 OCEntityHandlerResult ProcessGetRequest(OCEntityHandlerRequest *ehRequest, OCRepPayload **payload)
490 OCEntityHandlerResult ehResult = OC_EH_ERROR;
493 OIC_LOG(ERROR, ES_RH_TAG, "Request is Null");
496 if (ehRequest->payload && ehRequest->payload->type != PAYLOAD_TYPE_REPRESENTATION)
498 OIC_LOG(ERROR, ES_RH_TAG, "Incoming payload not a representation");
502 OCRepPayload *getResp = NULL;
504 if(ehRequest->resource == gProvResource.handle)
505 getResp = constructResponseOfProv(ehRequest);
506 else if(ehRequest->resource == gWiFiResource.handle)
507 getResp = constructResponseOfWiFi(ehRequest);
508 else if(ehRequest->resource == gCloudResource.handle)
509 getResp = constructResponseOfCloud(ehRequest);
510 else if(ehRequest->resource == gDevConfResource.handle)
511 getResp = constructResponseOfDevConf(ehRequest);
515 OIC_LOG(ERROR, ES_RH_TAG, "constructResponse failed");
525 OCEntityHandlerResult ProcessPostRequest(OCEntityHandlerRequest *ehRequest, OCRepPayload** payload)
527 OIC_LOG(INFO, ES_RH_TAG, "ProcessPostRequest enter");
528 OCEntityHandlerResult ehResult = OC_EH_ERROR;
529 if (ehRequest->payload && ehRequest->payload->type != PAYLOAD_TYPE_REPRESENTATION)
531 OIC_LOG(ERROR, ES_RH_TAG, "Incoming payload not a representation");
535 OCRepPayload* input = (OCRepPayload*) (ehRequest->payload);
538 OIC_LOG(ERROR, ES_RH_TAG, "Failed to parse");
542 if(ehRequest->resource == gProvResource.handle)
543 updateProvResource(ehRequest, input);
544 else if(ehRequest->resource == gWiFiResource.handle)
545 updateWiFiResource(ehRequest, input);
546 else if(ehRequest->resource == gCloudResource.handle)
547 updateCloudResource(ehRequest, input);
548 else if(ehRequest->resource == gDevConfResource.handle)
549 updateDevConfResource(ehRequest, input);
551 // ES_PS_PROVISIONING_COMPLETED state indicates that already provisioning is completed.
552 // A new request for provisioning means overriding existing network provisioning information.
553 if (gProvResource.trigger)
555 OIC_LOG(DEBUG, ES_RH_TAG, "Provisioning already completed."
556 "Tiggering the network connection");
558 if (gNetworkInfoProvEventCb)
560 gNetworkInfoProvEventCb(ES_RECVTRIGGEROFPROVRES);
565 OIC_LOG(ERROR, ES_RH_TAG, "gNetworkInfoProvEventCb is NULL."
566 "Network handler not registered. Failed to connect to the network");
567 ehResult = OC_EH_ERROR;
573 OIC_LOG(DEBUG, ES_RH_TAG, "Provisioning the network information to the Enrollee.");
576 OCRepPayload *getResp = NULL;
577 if(ehRequest->resource == gProvResource.handle)
578 getResp = constructResponseOfProv(ehRequest);
579 else if(ehRequest->resource == gWiFiResource.handle)
580 getResp = constructResponseOfWiFi(ehRequest);
581 else if(ehRequest->resource == gCloudResource.handle)
582 getResp = constructResponseOfCloud(ehRequest);
583 else if(ehRequest->resource == gDevConfResource.handle)
584 getResp = constructResponseOfDevConf(ehRequest);
586 if (gProvResource.trigger)// Trigger false should be restored after executed
587 gProvResource.trigger = false;
591 OIC_LOG(ERROR, ES_RH_TAG, "constructResponse failed");
601 OCEntityHandlerResult ProcessPutRequest(OCEntityHandlerRequest * ehRequest,
602 OCRepPayload** payload)
606 OCEntityHandlerResult ehResult = OC_EH_ERROR;
611 * This is the entity handler for the registered resource.
612 * This is invoked by OCStack whenever it recevies a request for this resource.
614 OCEntityHandlerResult OCEntityHandlerCb(OCEntityHandlerFlag flag,
615 OCEntityHandlerRequest* entityHandlerRequest, void *callback)
618 OCEntityHandlerResult ehRet = OC_EH_OK;
619 OCEntityHandlerResponse response =
620 { 0, 0, OC_EH_ERROR, 0, 0,
623 OCRepPayload* payload = NULL;
625 if (entityHandlerRequest && (flag & OC_REQUEST_FLAG))
627 if (OC_REST_GET == entityHandlerRequest->method)
629 OIC_LOG(INFO, ES_RH_TAG, "Received GET request");
630 ehRet = ProcessGetRequest(entityHandlerRequest, &payload);
632 else if (OC_REST_PUT == entityHandlerRequest->method)
634 OIC_LOG(INFO, ES_RH_TAG, "Received PUT request");
636 //PUT request will be handled in the internal implementation
637 if (gProvResource.handle != NULL)
639 ehRet = ProcessPutRequest(entityHandlerRequest, &payload);
643 OIC_LOG(ERROR, ES_RH_TAG, "Cannot process put");
647 else if (OC_REST_POST == entityHandlerRequest->method)
649 OIC_LOG(INFO, ES_RH_TAG, "Received OC_REST_POST from client");
650 if (gProvResource.handle != NULL)
652 ehRet = ProcessPostRequest(entityHandlerRequest, &payload);
656 OIC_LOG(ERROR, ES_RH_TAG, "Cannot process put");
661 if (ehRet == OC_EH_OK)
663 // Format the response. Note this requires some info about the request
664 response.requestHandle = entityHandlerRequest->requestHandle;
665 response.resourceHandle = entityHandlerRequest->resource;
666 response.ehResult = ehRet;
667 //response uses OCPaylod while all get,put methodes use OCRepPayload
668 response.payload = (OCPayload*) (payload);
669 response.numSendVendorSpecificHeaderOptions = 0;
670 memset(response.sendVendorSpecificHeaderOptions, 0,
671 sizeof(response.sendVendorSpecificHeaderOptions));
672 memset(response.resourceUri, 0, sizeof(response.resourceUri));
673 // Indicate that response is NOT in a persistent buffer
674 response.persistentBufferFlag = 0;
677 if (OCDoResponse(&response) != OC_STACK_OK)
679 OIC_LOG(ERROR, ES_RH_TAG, "Error sending response");
688 const char *getResult(OCStackResult result)
693 return "OC_STACK_OK";
694 case OC_STACK_INVALID_URI:
695 return "OC_STACK_INVALID_URI";
696 case OC_STACK_INVALID_QUERY:
697 return "OC_STACK_INVALID_QUERY";
698 case OC_STACK_INVALID_IP:
699 return "OC_STACK_INVALID_IP";
700 case OC_STACK_INVALID_PORT:
701 return "OC_STACK_INVALID_PORT";
702 case OC_STACK_INVALID_CALLBACK:
703 return "OC_STACK_INVALID_CALLBACK";
704 case OC_STACK_INVALID_METHOD:
705 return "OC_STACK_INVALID_METHOD";
706 case OC_STACK_NO_MEMORY:
707 return "OC_STACK_NO_MEMORY";
708 case OC_STACK_COMM_ERROR:
709 return "OC_STACK_COMM_ERROR";
710 case OC_STACK_INVALID_PARAM:
711 return "OC_STACK_INVALID_PARAM";
712 case OC_STACK_NOTIMPL:
713 return "OC_STACK_NOTIMPL";
714 case OC_STACK_NO_RESOURCE:
715 return "OC_STACK_NO_RESOURCE";
716 case OC_STACK_RESOURCE_ERROR:
717 return "OC_STACK_RESOURCE_ERROR";
718 case OC_STACK_SLOW_RESOURCE:
719 return "OC_STACK_SLOW_RESOURCE";
720 case OC_STACK_NO_OBSERVERS:
721 return "OC_STACK_NO_OBSERVERS";
723 return "OC_STACK_ERROR";