1 //******************************************************************
3 // Copyright 2014 Intel Mobile Communications GmbH 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 #define _POSIX_C_SOURCE 200112L
24 #include "ocstackconfig.h"
25 #include "ocstackinternal.h"
26 #include "ocresourcehandler.h"
27 #include "ocobserve.h"
28 #include "occollection.h"
35 #define TAG PCF("ocresource")
36 #define VERIFY_SUCCESS(op, successCode) { if (op != successCode) \
37 {OC_LOG_V(FATAL, TAG, "%s failed!!", #op); goto exit;} }
39 #define VERIFY_NON_NULL(arg, logLevel, retVal) { if (!(arg)) { OC_LOG((logLevel), \
40 TAG, PCF(#arg " is NULL")); return (retVal); } }
42 extern OCResource *headResource;
43 static cJSON *savedDeviceInfo = NULL;
45 static const char * VIRTUAL_RSRCS[] = {
54 //-----------------------------------------------------------------------------
55 // Default resource entity handler function
56 //-----------------------------------------------------------------------------
57 OCEntityHandlerResult defaultResourceEHandler(OCEntityHandlerFlag flag,
58 OCEntityHandlerRequest * request) {
59 TODO ("Implement me!!!!");
60 // TODO: remove silence unused param warnings
63 return OC_EH_OK; // Making sure that the Default EH and the Vendor EH have matching signatures
66 static OCStackResult ValidateUrlQuery (unsigned char *url, unsigned char *query,
67 uint8_t *filterOn, char **filterValue)
71 OC_LOG(INFO, TAG, PCF("Entering ValidateUrlQuery"));
73 return OC_STACK_INVALID_URI;
75 if (strcmp ((char *)url, GetVirtualResourceUri(OC_WELL_KNOWN_URI)) == 0 ||
76 strcmp ((char *)url, GetVirtualResourceUri(OC_DEVICE_URI)) == 0) {
77 *filterOn = STACK_RES_DISCOVERY_NOFILTER;
78 if (query && *query) {
80 filterParam = strtok_r((char *)query, "=", &strTokPtr);
81 *filterValue = strtok_r(NULL, " ", &strTokPtr);
82 if (!(*filterValue)) {
83 return OC_STACK_INVALID_QUERY;
84 } else if (strcmp (filterParam, OC_RSRVD_INTERFACE) == 0) {
85 // Resource discovery with interface filter
86 *filterOn = STACK_RES_DISCOVERY_IF_FILTER;
87 } else if (strcmp (filterParam, OC_RSRVD_RESOURCE_TYPE) == 0) {
88 // Resource discovery with resource type filter
89 *filterOn = STACK_RES_DISCOVERY_RT_FILTER;
90 } else if (strcmp (filterParam, OC_RSRVD_DEVICE_ID) == 0) {
92 *filterOn = STACK_DEVICE_DISCOVERY_DI_FILTER;
93 } else if (strcmp (filterParam, OC_RSRVD_DEVICE_NAME) == 0) {
95 *filterOn = STACK_DEVICE_DISCOVERY_DN_FILTER;
97 // Other filter types not supported
98 return OC_STACK_INVALID_QUERY;
103 else if (strcmp((char *)url, GetVirtualResourceUri(OC_PRESENCE)) == 0) {
104 //Nothing needs to be done, except for pass a OC_PRESENCE query through as OC_STACK_OK.
105 OC_LOG(INFO, TAG, PCF("OC_PRESENCE Request"));
106 *filterOn = STACK_RES_DISCOVERY_NOFILTER;
110 // Other URIs not yet supported
111 return OC_STACK_INVALID_URI;
113 OC_LOG(INFO, TAG, PCF("Exiting ValidateUrlQuery"));
117 OCStackResult BuildVirtualResourceResponse(OCResource *resourcePtr, uint8_t filterOn,
118 char *filterValue, char * out, uint16_t *remaining)
120 OCResourceType *resourceTypePtr;
121 OCResourceInterface *interfacePtr;
122 cJSON *resObj, *propObj, *rtArray;
124 uint8_t encodeRes = 0;
125 OCStackResult ret = OC_STACK_OK;
128 OC_LOG(INFO, TAG, PCF("Entering BuildVirtualResourceResponse"));
129 resObj = cJSON_CreateObject();
134 if (filterOn == STACK_RES_DISCOVERY_RT_FILTER) {
135 resourceTypePtr = resourcePtr->rsrcType;
136 while (resourceTypePtr) {
137 if (strcmp (resourceTypePtr->resourcetypename, filterValue) == 0) {
141 resourceTypePtr = resourceTypePtr->next;
143 } else if (filterOn == STACK_RES_DISCOVERY_IF_FILTER) {
144 interfacePtr = resourcePtr->rsrcInterface;
145 while (interfacePtr) {
146 if (strcmp (interfacePtr->name, filterValue) == 0) {
150 interfacePtr = interfacePtr->next;
152 } else if (filterOn == STACK_RES_DISCOVERY_NOFILTER) {
155 //TODO: Unsupported query filter
156 return OC_STACK_INVALID_QUERY;
161 cJSON_AddItemToObject (resObj, OC_RSRVD_HREF, cJSON_CreateString(resourcePtr->uri));
163 cJSON_AddItemToObject (resObj, "prop", propObj = cJSON_CreateObject());
164 // Add resource types
165 cJSON_AddItemToObject (propObj, OC_RSRVD_RESOURCE_TYPE, rtArray = cJSON_CreateArray());
166 resourceTypePtr = resourcePtr->rsrcType;
167 while (resourceTypePtr) {
168 cJSON_AddItemToArray (rtArray,
169 cJSON_CreateString(resourceTypePtr->resourcetypename));
170 resourceTypePtr = resourceTypePtr->next;
172 // Add interface types
173 cJSON_AddItemToObject (propObj, OC_RSRVD_INTERFACE, rtArray = cJSON_CreateArray());
174 interfacePtr = resourcePtr->rsrcInterface;
175 while (interfacePtr) {
176 cJSON_AddItemToArray (rtArray, cJSON_CreateString(interfacePtr->name));
177 interfacePtr = interfacePtr->next;
179 // If resource is observable, set observability flag.
180 // Resources that are not observable will not have the flag.
181 if (resourcePtr->resourceProperties & OC_OBSERVABLE) {
182 cJSON_AddItemToObject (propObj, OC_RSRVD_OBSERVABLE,
183 cJSON_CreateNumber(OC_RESOURCE_OBSERVABLE));
185 // Set secure flag for secure resources
186 if (resourcePtr->resourceProperties & OC_SECURE) {
188 cJSON_AddNumberToObject (propObj, OC_RSRVD_SECURE, OC_RESOURCE_SECURE);
189 //Set the IP port also as secure resources are hosted on a different port
190 if (OCGetResourceEndPointInfo (resourcePtr, &port) == OC_STACK_OK) {
191 cJSON_AddNumberToObject (propObj, OC_RSRVD_HOSTING_PORT, port);
197 jsonStr = cJSON_PrintUnformatted (resObj);
199 jsonLen = strlen(jsonStr);
200 if (jsonLen < *remaining)
202 strcpy(out, jsonStr);
203 *remaining = *remaining - jsonLen;
207 ret = OC_STACK_ERROR;
209 cJSON_Delete (resObj);
212 OC_LOG(INFO, TAG, PCF("Exiting BuildVirtualResourceResponse"));
216 OCStackResult BuildVirtualResourceResponseForDevice(uint8_t filterOn, char *filterValue,
217 char *out, uint16_t *remaining)
219 OCStackResult ret = OC_STACK_ERROR;
221 if (savedDeviceInfo != NULL)
223 char *jsonStr = NULL;
224 uint16_t jsonLen = 0;
225 cJSON *repObj = cJSON_GetObjectItem(savedDeviceInfo, "rep");
227 OC_LOG(INFO, TAG, PCF("Entering BuildVirtualResourceResponseForDevice"));
229 if (filterOn == STACK_DEVICE_DISCOVERY_DI_FILTER)
231 if((cJSON_GetObjectItem(repObj,"di") != NULL) &&
232 strcmp(cJSON_GetObjectItem(repObj,"di")->valuestring, filterValue) == 0)
237 else if (filterOn == STACK_DEVICE_DISCOVERY_DN_FILTER)
239 if((cJSON_GetObjectItem(repObj,"dn") != NULL) &&
240 strcmp(cJSON_GetObjectItem(repObj,"dn")->valuestring, filterValue) == 0)
245 else if (filterOn == STACK_RES_DISCOVERY_NOFILTER)
251 ret = OC_STACK_INVALID_QUERY;
254 if (ret == OC_STACK_OK)
256 jsonStr = cJSON_PrintUnformatted (savedDeviceInfo);
260 jsonLen = strlen(jsonStr);
262 if (jsonLen < *remaining)
264 strncpy(out, jsonStr, (jsonLen + 1));
265 *remaining = *remaining - jsonLen;
270 ret = OC_STACK_ERROR;
277 ret = OC_STACK_ERROR;
282 ret = OC_STACK_INVALID_DEVICE_INFO;
287 //error so that stack won't respond with empty payload
288 ret = OC_STACK_INVALID_DEVICE_INFO;
291 OC_LOG(INFO, TAG, PCF("Exiting BuildVirtualResourceResponseForDevice"));
295 TODO ("Does it make sense to make this method as inline")
296 const char * GetVirtualResourceUri( OCVirtualResources resource)
298 if (resource < OC_MAX_VIRTUAL_RESOURCES)
300 return VIRTUAL_RSRCS[resource];
306 uint8_t IsVirtualResource(const char* resourceUri)
308 for (int i = 0; i < OC_MAX_VIRTUAL_RESOURCES; i++)
310 if (strcmp(resourceUri, GetVirtualResourceUri((OCVirtualResources)i)) == 0)
318 uint8_t IsCollectionResource (OCResource *resource)
320 for (int i = 0; i < MAX_CONTAINED_RESOURCES; i++)
322 if (resource->rsrcResources[i])
330 OCResource *FindResourceByUri(const char* resourceUri)
332 OCResource * pointer = headResource;
334 if (strcmp(resourceUri, pointer->uri) == 0) {
337 pointer = pointer->next;
339 OC_LOG(INFO, TAG, PCF("Resource not found"));
344 OCStackResult DetermineResourceHandling (OCServerRequest *request,
345 ResourceHandling *handling,
346 OCResource **resource)
349 OC_LOG(INFO, TAG, PCF("Entering DetermineResourceHandling"));
351 // Check if virtual resource
352 if (IsVirtualResource((const char*)request->resourceUrl))
354 *handling = OC_RESOURCE_VIRTUAL;
355 *resource = headResource;
358 if (NULL == request->resourceUrl || (strlen((const char*)(request->resourceUrl)) == 0))
360 // Resource URL not specified
361 *handling = OC_RESOURCE_NOT_SPECIFIED;
366 OCResource *resourcePtr = NULL;
367 resourcePtr = FindResourceByUri((const char*)request->resourceUrl);
368 *resource = resourcePtr;
371 if(defaultDeviceHandler)
373 *handling = OC_RESOURCE_DEFAULT_DEVICE_ENTITYHANDLER;
377 // Resource does not exist
378 // and default device handler does not exist
379 *handling = OC_RESOURCE_NOT_SPECIFIED;
380 return OC_STACK_NO_RESOURCE;
383 // secure resource will entertain only authorized requests
384 if ((resourcePtr->resourceProperties & OC_SECURE) && (request->secured == 0))
386 OC_LOG(INFO, TAG, PCF("Un-authorized request. Ignore it!"));
387 return OC_STACK_RESOURCE_ERROR;
390 if (IsCollectionResource (resourcePtr))
392 // Collection resource
393 if (resourcePtr->entityHandler != defaultResourceEHandler)
395 *handling = OC_RESOURCE_COLLECTION_WITH_ENTITYHANDLER;
398 *handling = OC_RESOURCE_COLLECTION_DEFAULT_ENTITYHANDLER;
402 // Resource not a collection
403 if (resourcePtr->entityHandler != defaultResourceEHandler)
405 *handling = OC_RESOURCE_NOT_COLLECTION_WITH_ENTITYHANDLER;
408 *handling = OC_RESOURCE_NOT_COLLECTION_DEFAULT_ENTITYHANDLER;
415 OCStackResult EntityHandlerCodeToOCStackCode(OCEntityHandlerResult ehResult)
417 OCStackResult result;
422 result = OC_STACK_OK;
425 result = OC_STACK_SLOW_RESOURCE;
428 result = OC_STACK_ERROR;
430 case OC_EH_FORBIDDEN:
431 result = OC_STACK_RESOURCE_ERROR;
433 case OC_EH_RESOURCE_CREATED:
434 result = OC_STACK_RESOURCE_CREATED;
436 case OC_EH_RESOURCE_DELETED:
437 result = OC_STACK_RESOURCE_DELETED;
440 result = OC_STACK_ERROR;
447 HandleVirtualResource (OCServerRequest *request, OCResource* resource)
449 OCStackResult result = OC_STACK_ERROR;
450 char *filterValue = NULL;
451 uint8_t filterOn = 0;
452 uint16_t remaining = 0;
453 unsigned char * ptr = NULL;
454 uint8_t firstLoopDone = 0;
455 unsigned char discoveryResBuf[MAX_RESPONSE_LENGTH] = {0};
457 OC_LOG(INFO, TAG, PCF("Entering HandleVirtualResource"));
459 result = ValidateUrlQuery (request->resourceUrl,
460 request->query, &filterOn,
463 if (result == OC_STACK_OK)
465 if (strcmp ((char *)request->resourceUrl, GetVirtualResourceUri(OC_WELL_KNOWN_URI)) == 0)
467 ptr = discoveryResBuf;
468 remaining = MAX_RESPONSE_LENGTH;
472 if((resource->resourceProperties & OC_ACTIVE)
473 && (resource->resourceProperties & OC_DISCOVERABLE))
475 // if there is data on the buffer, we have already added a response,
476 // so we need to add a comma before we do anything
478 && remaining >= (sizeof(OC_JSON_SEPARATOR)+1))
480 *ptr = OC_JSON_SEPARATOR;
485 result = BuildVirtualResourceResponse(resource, filterOn, filterValue,
486 (char*)ptr, &remaining);
488 if (result != OC_STACK_OK)
490 // if this failed, we need to remove the comma added above.
499 ptr += strlen((char *)ptr);
502 resource = resource->next;
505 if(strlen((const char *)discoveryResBuf) > 0)
507 OCEntityHandlerResponse response = {0};
509 response.ehResult = OC_EH_OK;
510 response.payload = discoveryResBuf;
511 response.payloadSize = strlen((const char *)discoveryResBuf) + 1;
512 response.persistentBufferFlag = 0;
513 response.requestHandle = (OCRequestHandle) request;
514 response.resourceHandle = (OCResourceHandle) resource;
516 result = OCDoResponse(&response);
519 else if (strcmp ((char *)request->resourceUrl, GetVirtualResourceUri(OC_DEVICE_URI)) == 0)
521 remaining = MAX_RESPONSE_LENGTH;
522 ptr = discoveryResBuf;
524 result = BuildVirtualResourceResponseForDevice(filterOn, filterValue,
525 (char*)ptr, &remaining);
527 if(result == OC_STACK_OK)
529 ptr += strlen((char*)ptr);
532 if(remaining < MAX_RESPONSE_LENGTH)
534 OCEntityHandlerResponse response = {0};
536 response.ehResult = OC_EH_OK;
537 response.payload = discoveryResBuf;
538 response.payloadSize = strlen((const char *)discoveryResBuf) + 1;
539 response.persistentBufferFlag = 0;
540 response.requestHandle = (OCRequestHandle) request;
541 response.resourceHandle = (OCResourceHandle) resource;
543 result = OCDoResponse(&response);
549 if(resource->resourceProperties & OC_ACTIVE){
550 SendPresenceNotification(NULL);
555 result = OC_STACK_VIRTUAL_DO_NOT_HANDLE;
560 HandleDefaultDeviceEntityHandler (OCServerRequest *request)
562 OCStackResult result = OC_STACK_OK;
563 OCEntityHandlerResult ehResult = OC_EH_ERROR;
564 OCEntityHandlerRequest ehRequest = {0};
566 OC_LOG(INFO, TAG, PCF("Entering HandleResourceWithDefaultDeviceEntityHandler"));
567 result = FormOCEntityHandlerRequest(&ehRequest, (OCRequestHandle) request,
568 request->method, (OCResourceHandle) NULL, request->query,
569 request->reqJSONPayload, request->numRcvdVendorSpecificHeaderOptions,
570 request->rcvdVendorSpecificHeaderOptions, (OCObserveAction)request->observationOption, (OCObservationId)0);
571 VERIFY_SUCCESS(result, OC_STACK_OK);
573 // At this point we know for sure that defaultDeviceHandler exists
574 ehResult = defaultDeviceHandler(OC_REQUEST_FLAG, &ehRequest,
575 (char*) request->resourceUrl);
576 if(ehResult == OC_EH_SLOW)
578 OC_LOG(INFO, TAG, PCF("This is a slow resource"));
579 request->slowFlag = 1;
581 else if(ehResult == OC_EH_ERROR)
583 FindAndDeleteServerRequest(request);
585 result = EntityHandlerCodeToOCStackCode(ehResult);
591 HandleResourceWithEntityHandler (OCServerRequest *request,
592 OCResource *resource,
593 uint8_t collectionResource)
595 OCStackResult result = OC_STACK_ERROR;
596 OCEntityHandlerResult ehResult = OC_EH_ERROR;
597 OCEntityHandlerFlag ehFlag = OC_REQUEST_FLAG;
598 ResourceObserver *resObs = NULL;
600 OCEntityHandlerRequest ehRequest = {0};
602 OC_LOG(INFO, TAG, PCF("Entering HandleResourceWithEntityHandler"));
603 result = FormOCEntityHandlerRequest(&ehRequest, (OCRequestHandle) request,
604 request->method, (OCResourceHandle) resource, request->query,
605 request->reqJSONPayload, request->numRcvdVendorSpecificHeaderOptions,
606 request->rcvdVendorSpecificHeaderOptions,
607 (OCObserveAction)request->observationOption, 0);
608 VERIFY_SUCCESS(result, OC_STACK_OK);
610 if(ehRequest.obsInfo.action == OC_OBSERVE_NO_OPTION)
612 OC_LOG(INFO, TAG, PCF("No observation requested"));
613 ehFlag = OC_REQUEST_FLAG;
615 else if(ehRequest.obsInfo.action == OC_OBSERVE_REGISTER &&
618 OC_LOG(INFO, TAG, PCF("Registering observation requested"));
619 result = GenerateObserverId(&ehRequest.obsInfo.obsId);
620 VERIFY_SUCCESS(result, OC_STACK_OK);
622 result = AddObserver ((const char*)(request->resourceUrl),
623 (const char *)(request->query),
624 ehRequest.obsInfo.obsId, &request->requestToken,
625 &request->requesterAddr, resource, request->qos);
626 if(result == OC_STACK_OK)
628 OC_LOG(DEBUG, TAG, PCF("Added observer successfully"));
629 request->observeResult = OC_STACK_OK;
630 ehFlag = (OCEntityHandlerFlag)(OC_REQUEST_FLAG | OC_OBSERVE_FLAG);
634 result = OC_STACK_OK;
635 request->observeResult = OC_STACK_ERROR;
636 OC_LOG(DEBUG, TAG, PCF("Observer Addition failed"));
637 ehFlag = OC_REQUEST_FLAG;
641 else if(ehRequest.obsInfo.action == OC_OBSERVE_DEREGISTER &&
644 OC_LOG(INFO, TAG, PCF("Deregistering observation requested"));
645 resObs = GetObserverUsingToken (&request->requestToken);
648 // Stack does not contain this observation request
649 // Either token is incorrect or observation list is corrupted
650 result = OC_STACK_ERROR;
653 ehRequest.obsInfo.obsId = resObs->observeId;
654 ehFlag = (OCEntityHandlerFlag)(ehFlag | OC_OBSERVE_FLAG);
656 result = DeleteObserverUsingToken (&request->requestToken);
657 if(result == OC_STACK_OK)
659 OC_LOG(DEBUG, TAG, PCF("Removed observer successfully"));
660 request->observeResult = OC_STACK_OK;
664 result = OC_STACK_OK;
665 request->observeResult = OC_STACK_ERROR;
666 OC_LOG(DEBUG, TAG, PCF("Observer Removal failed"));
671 result = OC_STACK_ERROR;
675 ehResult = resource->entityHandler(ehFlag, &ehRequest);
676 if(ehResult == OC_EH_SLOW)
678 OC_LOG(INFO, TAG, PCF("This is a slow resource"));
679 request->slowFlag = 1;
681 else if(ehResult == OC_EH_ERROR)
683 FindAndDeleteServerRequest(request);
685 result = EntityHandlerCodeToOCStackCode(ehResult);
691 HandleCollectionResourceDefaultEntityHandler (OCServerRequest *request,
692 OCResource *resource)
694 OCStackResult result = OC_STACK_ERROR;
695 OCEntityHandlerRequest ehRequest = {0};
697 result = FormOCEntityHandlerRequest(&ehRequest, (OCRequestHandle) request,
698 request->method, (OCResourceHandle) resource, request->query,
699 request->reqJSONPayload, request->numRcvdVendorSpecificHeaderOptions,
700 request->rcvdVendorSpecificHeaderOptions,
701 (OCObserveAction)request->observationOption, (OCObservationId) 0);
702 if(result != OC_STACK_OK)
707 return (DefaultCollectionEntityHandler (OC_REQUEST_FLAG, &ehRequest));
711 ProcessRequest(ResourceHandling resHandling, OCResource *resource, OCServerRequest *request)
713 OCStackResult ret = OC_STACK_OK;
717 case OC_RESOURCE_VIRTUAL:
719 ret = HandleVirtualResource (request, resource);
722 case OC_RESOURCE_DEFAULT_DEVICE_ENTITYHANDLER:
724 ret = HandleDefaultDeviceEntityHandler(request);
727 case OC_RESOURCE_NOT_COLLECTION_DEFAULT_ENTITYHANDLER:
729 OC_LOG(INFO, TAG, PCF("OC_RESOURCE_NOT_COLLECTION_DEFAULT_ENTITYHANDLER"));
730 return OC_STACK_ERROR;
732 case OC_RESOURCE_NOT_COLLECTION_WITH_ENTITYHANDLER:
734 ret = HandleResourceWithEntityHandler (request, resource, 0);
737 case OC_RESOURCE_COLLECTION_WITH_ENTITYHANDLER:
739 ret = HandleResourceWithEntityHandler (request, resource, 1);
742 case OC_RESOURCE_COLLECTION_DEFAULT_ENTITYHANDLER:
744 ret = HandleCollectionResourceDefaultEntityHandler (request, resource);
747 case OC_RESOURCE_NOT_SPECIFIED:
749 ret = OC_STACK_NO_RESOURCE;
754 OC_LOG(INFO, TAG, PCF("Invalid Resource Determination"));
755 return OC_STACK_ERROR;
761 void DeleteDeviceInfo()
765 cJSON_Delete(savedDeviceInfo);
769 OCStackResult SaveDeviceInfo(OCDeviceInfo deviceInfo)
773 savedDeviceInfo = cJSON_CreateObject();
774 cJSON *repObj = NULL;
776 cJSON_AddItemToObject (savedDeviceInfo, OC_RSRVD_HREF,
777 cJSON_CreateString(GetVirtualResourceUri(OC_DEVICE_URI)));
779 cJSON_AddItemToObject (savedDeviceInfo, "rep", repObj = cJSON_CreateObject());
781 if (deviceInfo.contentType)
783 cJSON_AddItemToObject (repObj, "ct",
784 cJSON_CreateString(deviceInfo.contentType));
787 if (deviceInfo.dateOfManufacture)
789 cJSON_AddItemToObject (repObj, "mndt",
790 cJSON_CreateString(deviceInfo.dateOfManufacture));
793 if (deviceInfo.deviceName)
795 cJSON_AddItemToObject (repObj, "dn",
796 cJSON_CreateString(deviceInfo.deviceName));
799 if (deviceInfo.deviceUUID)
801 cJSON_AddItemToObject (repObj, "di",
802 cJSON_CreateString(deviceInfo.deviceUUID));
805 if (deviceInfo.firmwareVersion)
807 cJSON_AddItemToObject (repObj, "mnfv",
808 cJSON_CreateString(deviceInfo.firmwareVersion));
811 if (deviceInfo.hostName)
813 cJSON_AddItemToObject (repObj, "hn", cJSON_CreateString(deviceInfo.hostName));
816 if (deviceInfo.manufacturerName)
818 if(strlen(deviceInfo.manufacturerName) > MAX_MANUFACTURER_NAME_LENGTH)
821 return OC_STACK_INVALID_PARAM;
824 cJSON_AddItemToObject (repObj, "mnmn",
825 cJSON_CreateString(deviceInfo.manufacturerName));
828 if (deviceInfo.manufacturerUrl)
830 if(strlen(deviceInfo.manufacturerUrl) > MAX_MANUFACTURER_URL_LENGTH)
833 return OC_STACK_INVALID_PARAM;
836 cJSON_AddItemToObject (repObj, "mnml",
837 cJSON_CreateString(deviceInfo.manufacturerUrl));
840 if (deviceInfo.modelNumber)
842 cJSON_AddItemToObject (repObj, "mnmo",
843 cJSON_CreateString(deviceInfo.modelNumber));
846 if (deviceInfo.platformVersion)
848 cJSON_AddItemToObject (repObj, "mnpv",
849 cJSON_CreateString(deviceInfo.platformVersion));
852 if (deviceInfo.supportUrl)
854 cJSON_AddItemToObject (repObj, "mnsl",
855 cJSON_CreateString(deviceInfo.supportUrl));
858 if (deviceInfo.version)
860 cJSON_AddItemToObject (repObj, "icv",
861 cJSON_CreateString(deviceInfo.version));