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)
94 OICFree(obj->messageId);
95 obj->messageId = NULL;
104 if (obj->contentText)
106 OICFree(obj->contentText);
107 obj->contentText = NULL;
112 OICFree(obj->sourceName);
113 obj->sourceName = NULL;
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->contentText = NULL;
133 newMsg->messageId = NULL;
134 newMsg->sourceName = NULL;
135 newMsg->title = NULL;
137 if (copyMsg->messageId)
139 newMsg->messageId = OICStrdup(copyMsg->messageId);
144 newMsg->title = OICStrdup(copyMsg->title);
147 if (copyMsg->contentText)
149 newMsg->contentText = OICStrdup(copyMsg->contentText);
152 if (copyMsg->sourceName)
154 newMsg->sourceName = OICStrdup(copyMsg->sourceName);
160 NSResult NSFreeSync(NSSyncInfo * obj)
169 OICFree(obj->messageId);
170 obj->messageId = NULL;
175 NS_LOG_V(DEBUG, "obj->mSourceid = %s", obj->providerId);
176 OICFree(obj->providerId);
177 obj->providerId = NULL;
185 NSSyncInfo* NSDuplicateSync(NSSyncInfo * copyMsg)
187 NSSyncInfo * newMsg = NULL;
191 NS_LOG(ERROR, "Copy Msg is NULL");
195 newMsg = (NSSyncInfo *)OICMalloc(sizeof(NSSyncInfo));
196 newMsg->messageId = NULL;
197 newMsg->providerId = NULL;
200 if (copyMsg->messageId)
202 newMsg->messageId = OICStrdup(copyMsg->messageId);
205 if (copyMsg->providerId)
207 newMsg->providerId = OICStrdup(copyMsg->providerId);
210 newMsg->state = copyMsg->state;
215 NSResult NSFreeConsumer(NSConsumer * obj)
224 OICFree(obj->mAddress);
225 obj->mAddress = NULL;
230 OICFree(obj->mDeviceId);
231 obj->mDeviceId = NULL;
239 NSConsumer* NSDuplicateConsumer(NSConsumer * copyMsg)
241 NSConsumer * newMsg = NULL;
245 NS_LOG(ERROR, "Copy Msg is NULL");
249 newMsg = (NSConsumer *)OICMalloc(sizeof(NSConsumer));
250 newMsg->mAddress = NULL;
251 newMsg->mDeviceId = NULL;
253 if (copyMsg->mAddress)
255 newMsg->mAddress = OICStrdup(copyMsg->mAddress);
258 if (copyMsg->mDeviceId)
260 newMsg->mDeviceId = OICStrdup(copyMsg->mDeviceId);
266 void NSDuplicateSetPropertyString(OCRepPayload** msgPayload, const char * name,
267 const char * copyString)
271 OCRepPayloadSetPropString(*msgPayload, name, copyString);
275 OCRepPayloadSetNull(*msgPayload, name);
280 NSSyncInfo * NSGetSyncInfo(OCPayload * payload)
282 NS_LOG(DEBUG, "NSBuildOICNotificationSync - IN");
288 NSSyncInfo * retSync = (NSSyncInfo *)OICMalloc(sizeof(NSSyncInfo));
294 retSync->messageId = NULL;
295 retSync->state = NS_SYNC_READ;
297 OCRepPayload * repPayload = (OCRepPayload *)payload;
298 if (!OCRepPayloadGetPropString(repPayload, NS_ATTRIBUTE_MESSAGE_ID, &retSync->messageId))
303 if (!OCRepPayloadGetPropString(repPayload, NS_ATTRIBUTE_PROVIDER_ID, &retSync->providerId))
309 if (!OCRepPayloadGetPropInt(repPayload, NS_ATTRIBUTE_STATE, &state))
311 OICFree(retSync->messageId);
316 retSync->state = (NSSyncType) state;
318 NS_LOG_V(DEBUG, "Sync ID : %s", retSync->messageId);
319 NS_LOG_V(DEBUG, "Sync State : %d", (int) retSync->state);
321 NS_LOG(DEBUG, "NSBuildOICNotificationSync - OUT");