1 //******************************************************************
3 // Copyright 2016 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 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
23 NSResult NSFreeMessage(NSMessage * obj)
42 if (obj->mContentText)
44 OICFree(obj->mContentText);
45 obj->mContentText = NULL;
50 OICFree(obj->mSource);
59 NSMessage * NSDuplicateMessage(NSMessage * copyMsg)
61 NSMessage * newMsg = NULL;
65 NS_LOG(ERROR, "Copy Msg is NULL");
69 newMsg = (NSMessage *)OICMalloc(sizeof(NSMessage));
73 newMsg->mId = OICStrdup(copyMsg->mId);
78 newMsg->mTitle = OICStrdup(copyMsg->mTitle);
81 if (copyMsg->mContentText)
83 newMsg->mContentText = OICStrdup(copyMsg->mContentText);
88 newMsg->mSource = OICStrdup(copyMsg->mSource);
94 OCEntityHandlerRequest *NSCopyOCEntityHandlerRequest(OCEntityHandlerRequest *entityHandlerRequest)
96 NS_LOG(DEBUG, "NSCopyOCEntityHandlerRequest - IN");
98 OCEntityHandlerRequest *copyOfRequest =
99 (OCEntityHandlerRequest *)OICMalloc(sizeof(OCEntityHandlerRequest));
104 memcpy(copyOfRequest, entityHandlerRequest, sizeof(OCEntityHandlerRequest));
107 if (copyOfRequest->query)
109 copyOfRequest->query = OICStrdup(entityHandlerRequest->query);
110 if(!copyOfRequest->query)
112 NS_LOG(ERROR, "Copy failed due to allocation failure");
113 OICFree(copyOfRequest);
118 if (entityHandlerRequest->payload)
120 copyOfRequest->payload = (OCPayload *)
121 (OCRepPayloadClone ((OCRepPayload*) entityHandlerRequest->payload));
124 // Ignore vendor specific header options for example
125 copyOfRequest->numRcvdVendorSpecificHeaderOptions = 0;
126 copyOfRequest->rcvdVendorSpecificHeaderOptions = NULL;
131 NS_LOG(DEBUG, "Copied client request");
135 NS_LOG(DEBUG, "Error copying client request");
138 NS_LOG(DEBUG, "NSCopyOCEntityHandlerRequest - OUT");
140 return copyOfRequest;
143 NSResult NSFreeOCEntityHandlerRequest(OCEntityHandlerRequest * entityHandlerRequest)
145 NS_LOG(DEBUG, "NSFreeOCEntityHandlerRequest - IN");
147 OICFree(entityHandlerRequest->query);
148 OCPayloadDestroy(entityHandlerRequest->payload);
149 OICFree(entityHandlerRequest);
151 NS_LOG(DEBUG, "NSFreeOCEntityHandlerRequest - OUT");