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)
63 NS_LOG(ERROR, "Copy Msg is NULL");
67 NSMessage * newMsg = (NSMessage *)OICMalloc(sizeof(NSMessage));
71 newMsg->mId = OICStrdup(copyMsg->mId);
76 newMsg->mTitle = OICStrdup(copyMsg->mTitle);
79 if (!copyMsg->mContentText)
81 newMsg->mContentText = OICStrdup(copyMsg->mContentText);
84 if (!copyMsg->mSource)
86 newMsg->mSource = OICStrdup(copyMsg->mSource);
92 OCEntityHandlerRequest *NSCopyOCEntityHandlerRequest(OCEntityHandlerRequest *entityHandlerRequest)
94 NS_LOG(DEBUG, "NSCopyOCEntityHandlerRequest - IN");
96 OCEntityHandlerRequest *copyOfRequest =
97 (OCEntityHandlerRequest *)OICMalloc(sizeof(OCEntityHandlerRequest));
102 memcpy(copyOfRequest, entityHandlerRequest, sizeof(OCEntityHandlerRequest));
105 if (copyOfRequest->query)
107 copyOfRequest->query = OICStrdup(entityHandlerRequest->query);
108 if(!copyOfRequest->query)
110 NS_LOG(ERROR, "Copy failed due to allocation failure");
111 OICFree(copyOfRequest);
116 if (entityHandlerRequest->payload)
118 copyOfRequest->payload = (OCPayload *)
119 (OCRepPayloadClone ((OCRepPayload*) entityHandlerRequest->payload));
122 // Ignore vendor specific header options for example
123 copyOfRequest->numRcvdVendorSpecificHeaderOptions = 0;
124 copyOfRequest->rcvdVendorSpecificHeaderOptions = NULL;
129 NS_LOG(DEBUG, "Copied client request");
133 NS_LOG(DEBUG, "Error copying client request");
136 NS_LOG(DEBUG, "NSCopyOCEntityHandlerRequest - OUT");
138 return copyOfRequest;
141 NSResult NSFreeOCEntityHandlerRequest(OCEntityHandlerRequest * entityHandlerRequest)
143 NS_LOG(DEBUG, "NSFreeOCEntityHandlerRequest - IN");
145 OICFree(entityHandlerRequest->query);
146 OCPayloadDestroy(entityHandlerRequest->payload);
147 OICFree(entityHandlerRequest);
149 NS_LOG(DEBUG, "NSFreeOCEntityHandlerRequest - OUT");