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 OCEntityHandlerRequest *NSCopyOCEntityHandlerRequest(OCEntityHandlerRequest *entityHandlerRequest)
25 NS_LOG(DEBUG, "NSCopyOCEntityHandlerRequest - IN");
27 OCEntityHandlerRequest *copyOfRequest =
28 (OCEntityHandlerRequest *)OICMalloc(sizeof(OCEntityHandlerRequest));
33 memcpy(copyOfRequest, entityHandlerRequest, sizeof(OCEntityHandlerRequest));
36 if (copyOfRequest->query)
38 copyOfRequest->query = OICStrdup(entityHandlerRequest->query);
39 if(!copyOfRequest->query)
41 NS_LOG(ERROR, "Copy failed due to allocation failure");
42 OICFree(copyOfRequest);
47 if (entityHandlerRequest->payload)
49 copyOfRequest->payload = (OCPayload *)
50 (OCRepPayloadClone ((OCRepPayload*) entityHandlerRequest->payload));
53 // Ignore vendor specific header options for example
54 copyOfRequest->numRcvdVendorSpecificHeaderOptions = 0;
55 copyOfRequest->rcvdVendorSpecificHeaderOptions = NULL;
60 NS_LOG(DEBUG, "Copied client request");
64 NS_LOG(DEBUG, "Error copying client request");
67 NS_LOG(DEBUG, "NSCopyOCEntityHandlerRequest - OUT");
72 NSResult NSFreeOCEntityHandlerRequest(OCEntityHandlerRequest * entityHandlerRequest)
74 NS_LOG(DEBUG, "NSFreeOCEntityHandlerRequest - IN");
76 OICFree(entityHandlerRequest->query);
77 OCPayloadDestroy(entityHandlerRequest->payload);
78 OICFree(entityHandlerRequest);
80 NS_LOG(DEBUG, "NSFreeOCEntityHandlerRequest - OUT");
85 NSResult NSFreeMessage(NSMessage * obj)
100 OICFree(obj->mTitle);
104 if (obj->mContentText)
106 OICFree(obj->mContentText);
107 obj->mContentText = NULL;
112 OICFree(obj->mSource);
121 NSMessage * NSDuplicateMessage(NSMessage * copyMsg)
123 NSMessage * newMsg = NULL;
127 NS_LOG(ERROR, "Copy Msg is NULL");
131 newMsg = (NSMessage *)OICMalloc(sizeof(NSMessage));
132 newMsg->mContentText = NULL;
134 newMsg->mSource = NULL;
135 newMsg->mTitle = NULL;
139 newMsg->mId = OICStrdup(copyMsg->mId);
144 newMsg->mTitle = OICStrdup(copyMsg->mTitle);
147 if (copyMsg->mContentText)
149 newMsg->mContentText = OICStrdup(copyMsg->mContentText);
152 if (copyMsg->mSource)
154 newMsg->mSource = OICStrdup(copyMsg->mSource);
160 NSResult NSFreeSync(NSSync * obj)
169 OICFree(obj->mMessageId);
170 obj->mMessageId = NULL;
175 OICFree(obj->mSourceId);
176 obj->mSourceId = NULL;
184 NSSync* NSDuplicateSync(NSSync * copyMsg)
186 NSSync * newMsg = NULL;
190 NS_LOG(ERROR, "Copy Msg is NULL");
194 newMsg = (NSSync *)OICMalloc(sizeof(NSSync));
195 newMsg->mMessageId = NULL;
196 newMsg->mSourceId = NULL;
199 if (copyMsg->mMessageId)
201 newMsg->mMessageId = OICStrdup(copyMsg->mMessageId);
204 if (copyMsg->mSourceId)
206 newMsg->mSourceId = OICStrdup(copyMsg->mSourceId);
212 NSResult NSFreeConsumer(NSConsumer * obj)
221 OICFree(obj->mAddress);
222 obj->mAddress = NULL;
227 OICFree(obj->mDeviceId);
228 obj->mDeviceId = NULL;
236 NSConsumer* NSDuplicateConsumer(NSConsumer * copyMsg)
238 NSConsumer * newMsg = NULL;
242 NS_LOG(ERROR, "Copy Msg is NULL");
246 newMsg = (NSConsumer *)OICMalloc(sizeof(NSConsumer));
247 newMsg->mAddress = NULL;
248 newMsg->mDeviceId = NULL;
250 if (copyMsg->mAddress)
252 newMsg->mAddress = OICStrdup(copyMsg->mAddress);
255 if (copyMsg->mDeviceId)
257 newMsg->mDeviceId = OICStrdup(copyMsg->mDeviceId);