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));
35 if (copyOfRequest->query)
37 copyOfRequest->query = OICStrdup(entityHandlerRequest->query);
38 if(!copyOfRequest->query)
40 NS_LOG(ERROR, "Copy failed due to allocation failure");
41 OICFree(copyOfRequest);
46 if (entityHandlerRequest->payload)
48 copyOfRequest->payload = (OCPayload *)
49 (OCRepPayloadClone ((OCRepPayload*) entityHandlerRequest->payload));
52 // Ignore vendor specific header options for example
53 copyOfRequest->numRcvdVendorSpecificHeaderOptions = 0;
54 copyOfRequest->rcvdVendorSpecificHeaderOptions = NULL;
59 NS_LOG(DEBUG, "Copied client request");
63 NS_LOG(DEBUG, "Error copying client request");
66 NS_LOG(DEBUG, "NSCopyOCEntityHandlerRequest - OUT");
71 NSResult NSFreeOCEntityHandlerRequest(OCEntityHandlerRequest * entityHandlerRequest)
73 NS_LOG(DEBUG, "NSFreeOCEntityHandlerRequest - IN");
75 OICFree(entityHandlerRequest->query);
76 OCPayloadDestroy(entityHandlerRequest->payload);
77 OICFree(entityHandlerRequest);
79 NS_LOG(DEBUG, "NSFreeOCEntityHandlerRequest - OUT");
84 NSResult NSFreeMessage(NSMessage * obj)
102 if (obj->contentText)
104 OICFree(obj->contentText);
105 obj->contentText = NULL;
110 OICFree(obj->sourceName);
111 obj->sourceName = NULL;
119 NSMessage * NSDuplicateMessage(NSMessage * copyMsg)
121 NSMessage * newMsg = NULL;
125 NS_LOG(ERROR, "Copy Msg is NULL");
129 newMsg = (NSMessage *)OICMalloc(sizeof(NSMessage));
130 newMsg->contentText = NULL;
131 newMsg->messageId = 0;
132 newMsg->sourceName = NULL;
133 newMsg->title = NULL;
135 if (copyMsg->messageId)
137 newMsg->messageId = copyMsg->messageId;
142 newMsg->title = OICStrdup(copyMsg->title);
145 if (copyMsg->contentText)
147 newMsg->contentText = OICStrdup(copyMsg->contentText);
150 if (copyMsg->sourceName)
152 newMsg->sourceName = OICStrdup(copyMsg->sourceName);
158 NSResult NSFreeSync(NSSyncInfo * obj)
170 NSSyncInfo* NSDuplicateSync(NSSyncInfo * copyMsg)
172 NSSyncInfo * newMsg = NULL;
176 NS_LOG(ERROR, "Copy Msg is NULL");
180 newMsg = (NSSyncInfo *)OICMalloc(sizeof(NSSyncInfo));
182 newMsg->messageId = copyMsg->messageId;
183 OICStrcpy(newMsg->providerId, UUID_STRING_SIZE, copyMsg->providerId);
184 newMsg->state = copyMsg->state;
189 NSResult NSFreeConsumer(NSConsumer * obj)
196 (obj->consumerId)[0] = '\0';
204 NSConsumer* NSDuplicateConsumer(NSConsumer * copyMsg)
206 NSConsumer * newMsg = NULL;
210 NS_LOG(ERROR, "Copy Msg is NULL");
214 newMsg = (NSConsumer *)OICMalloc(sizeof(NSConsumer));
215 (newMsg->consumerId)[0] = '\0';
217 OICStrcpy(newMsg->consumerId, UUID_STRING_SIZE, copyMsg->consumerId);
222 void NSDuplicateSetPropertyString(OCRepPayload** msgPayload, const char * name,
223 const char * copyString)
227 OCRepPayloadSetPropString(*msgPayload, name, copyString);
232 NSSyncInfo * NSGetSyncInfo(OCPayload * payload)
234 NS_LOG(DEBUG, "NSGetSyncInfo - IN");
235 char * providerId = NULL;
242 NSSyncInfo * retSync = (NSSyncInfo *)OICMalloc(sizeof(NSSyncInfo));
248 retSync->messageId = 0;
249 retSync->state = NS_SYNC_READ;
251 OCRepPayload * repPayload = (OCRepPayload *)payload;
252 if (!OCRepPayloadGetPropInt(repPayload, NS_ATTRIBUTE_MESSAGE_ID, (int64_t *)&retSync->messageId))
258 if (!OCRepPayloadGetPropString(repPayload, NS_ATTRIBUTE_PROVIDER_ID, &providerId))
264 if (!OCRepPayloadGetPropInt(repPayload, NS_ATTRIBUTE_STATE, &state))
270 retSync->state = (NSSyncType) state;
271 OICStrcpy(retSync->providerId, UUID_STRING_SIZE, providerId);
274 NS_LOG_V(DEBUG, "Provider ID : %s", retSync->providerId);
275 NS_LOG_V(DEBUG, "Sync ID : %ld", retSync->messageId);
276 NS_LOG_V(DEBUG, "Sync State : %d", (int) retSync->state);
278 NS_LOG(DEBUG, "NSGetSyncInfo - OUT");
283 NSResult NSGenerateUUIDStr(char uuidStr[UUID_STRING_SIZE])
285 uint8_t uuid[UUID_SIZE] = { 0, };
287 if (RAND_UUID_OK == OCGenerateUuid(uuid))
289 if (RAND_UUID_OK == OCConvertUuidToString(uuid, uuidStr))
297 char * NSGetValueFromQuery(char *query, char * compareKey)
302 char *restOfQuery = NULL;
303 int numKeyValuePairsParsed = 0;
305 NS_LOG_V(INFO, "NS Query Params = %s", query);
307 char *keyValuePair = strtok_r (query, NS_QUERY_SEPARATOR, &restOfQuery);
311 if (numKeyValuePairsParsed >= 2)
313 NS_LOG(ERROR, "More than 2 queries params in URI.");
317 key = strtok_r(keyValuePair, NS_KEY_VALUE_DELIMITER, &value);
321 NS_LOG(ERROR, "More than 2 queries params in URI.");
325 if (strcmp(key, compareKey) == 0)
330 ++numKeyValuePairsParsed;
332 keyValuePair = strtok_r(NULL, NS_QUERY_SEPARATOR, &restOfQuery);