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)
103 if (obj->contentText)
105 OICFree(obj->contentText);
106 obj->contentText = NULL;
111 OICFree(obj->sourceName);
112 obj->sourceName = NULL;
120 NSMessage * NSDuplicateMessage(NSMessage * copyMsg)
122 NSMessage * newMsg = NULL;
126 NS_LOG(ERROR, "Copy Msg is NULL");
130 newMsg = (NSMessage *)OICMalloc(sizeof(NSMessage));
131 newMsg->contentText = NULL;
132 newMsg->messageId = 0;
133 newMsg->sourceName = NULL;
134 newMsg->title = NULL;
136 if (copyMsg->messageId)
138 newMsg->messageId = copyMsg->messageId;
143 newMsg->title = OICStrdup(copyMsg->title);
146 if (copyMsg->contentText)
148 newMsg->contentText = OICStrdup(copyMsg->contentText);
151 if (copyMsg->sourceName)
153 newMsg->sourceName = OICStrdup(copyMsg->sourceName);
159 NSResult NSFreeSync(NSSyncInfo * obj)
173 NS_LOG_V(DEBUG, "obj->mSourceid = %s", obj->providerId);
174 OICFree(obj->providerId);
175 obj->providerId = NULL;
183 NSSyncInfo* NSDuplicateSync(NSSyncInfo * copyMsg)
185 NSSyncInfo * newMsg = NULL;
189 NS_LOG(ERROR, "Copy Msg is NULL");
193 newMsg = (NSSyncInfo *)OICMalloc(sizeof(NSSyncInfo));
194 newMsg->messageId = 0;
195 newMsg->providerId = NULL;
198 if (copyMsg->messageId)
200 newMsg->messageId = copyMsg->messageId;
203 if (copyMsg->providerId)
205 newMsg->providerId = OICStrdup(copyMsg->providerId);
208 newMsg->state = copyMsg->state;
213 NSResult NSFreeConsumer(NSConsumer * obj)
222 OICFree(obj->mAddress);
223 obj->mAddress = NULL;
228 OICFree(obj->mDeviceId);
229 obj->mDeviceId = NULL;
237 NSConsumer* NSDuplicateConsumer(NSConsumer * copyMsg)
239 NSConsumer * newMsg = NULL;
243 NS_LOG(ERROR, "Copy Msg is NULL");
247 newMsg = (NSConsumer *)OICMalloc(sizeof(NSConsumer));
248 newMsg->mAddress = NULL;
249 newMsg->mDeviceId = NULL;
251 if (copyMsg->mAddress)
253 newMsg->mAddress = OICStrdup(copyMsg->mAddress);
256 if (copyMsg->mDeviceId)
258 newMsg->mDeviceId = OICStrdup(copyMsg->mDeviceId);
264 void NSDuplicateSetPropertyString(OCRepPayload** msgPayload, const char * name,
265 const char * copyString)
269 OCRepPayloadSetPropString(*msgPayload, name, copyString);
273 OCRepPayloadSetNull(*msgPayload, name);
278 NSSyncInfo * NSGetSyncInfo(OCPayload * payload)
280 NS_LOG(DEBUG, "NSBuildOICNotificationSync - IN");
286 NSSyncInfo * retSync = (NSSyncInfo *)OICMalloc(sizeof(NSSyncInfo));
292 retSync->messageId = 0;
293 retSync->state = NS_SYNC_READ;
295 OCRepPayload * repPayload = (OCRepPayload *)payload;
296 if (!OCRepPayloadGetPropInt(repPayload, NS_ATTRIBUTE_MESSAGE_ID, (int64_t *)&retSync->messageId))
301 if (!OCRepPayloadGetPropString(repPayload, NS_ATTRIBUTE_PROVIDER_ID, &retSync->providerId))
307 if (!OCRepPayloadGetPropInt(repPayload, NS_ATTRIBUTE_STATE, &state))
313 retSync->state = (NSSyncType) state;
315 NS_LOG_V(DEBUG, "Sync ID : %ld", retSync->messageId);
316 NS_LOG_V(DEBUG, "Sync State : %d", (int) retSync->state);
318 NS_LOG(DEBUG, "NSBuildOICNotificationSync - OUT");