-void NSGetProviderPostClean(
- char * pId, char * mUri, char * sUri, NSProviderConnectionInfo * connection)
-{
- NSOICFree(pId);
- NSOICFree(mUri);
- NSOICFree(sUri);
- NSRemoveConnections(connection);
-}
-
-NSProvider_internal * NSGetProvider(OCClientResponse * clientResponse)
-{
- NS_LOG(DEBUG, "create NSProvider");
- NS_VERIFY_NOT_NULL(clientResponse->payload, NULL);
-
- OCRepPayload * payload = (OCRepPayload *)clientResponse->payload;
- while (payload)
- {
- NS_LOG_V(DEBUG, "Payload Key : %s", payload->values->name);
- payload = payload->next;
- }
-
- payload = (OCRepPayload *)clientResponse->payload;
-
- char * providerId = NULL;
- char * messageUri = NULL;
- char * syncUri = NULL;
- int64_t accepter = 0;
- NSProviderConnectionInfo * connection = NULL;
-
- NS_LOG(DEBUG, "get information of accepter");
- bool getResult = OCRepPayloadGetPropInt(payload, NS_ATTRIBUTE_POLICY, & accepter);
- NS_VERIFY_NOT_NULL(getResult == true ? (void *) 1 : NULL, NULL);
-
- NS_LOG(DEBUG, "get provider ID");
- getResult = OCRepPayloadGetPropString(payload, NS_ATTRIBUTE_PROVIDER_ID, & providerId);
- NS_VERIFY_NOT_NULL(getResult == true ? (void *) 1 : NULL, NULL);
-
- NS_LOG(DEBUG, "get message URI");
- getResult = OCRepPayloadGetPropString(payload, NS_ATTRIBUTE_MESSAGE, & messageUri);
- NS_VERIFY_NOT_NULL_WITH_POST_CLEANING(getResult == true ? (void *) 1 : NULL, NULL,
- NSGetProviderPostClean(providerId, messageUri, syncUri, connection));
-
- NS_LOG(DEBUG, "get sync URI");
- getResult = OCRepPayloadGetPropString(payload, NS_ATTRIBUTE_SYNC, & syncUri);
- NS_VERIFY_NOT_NULL_WITH_POST_CLEANING(getResult == true ? (void *) 1 : NULL, NULL,
- NSGetProviderPostClean(providerId, messageUri, syncUri, connection));
-
- NS_LOG(DEBUG, "get provider connection information");
- NS_VERIFY_NOT_NULL(clientResponse->addr, NULL);
- connection = NSCreateProviderConnections(clientResponse->addr);
- NS_VERIFY_NOT_NULL(connection, NULL);
-
- NSProvider_internal * newProvider
- = (NSProvider_internal *)OICMalloc(sizeof(NSProvider_internal));
- NS_VERIFY_NOT_NULL_WITH_POST_CLEANING(newProvider, NULL,
- NSGetProviderPostClean(providerId, messageUri, syncUri, connection));
-
- OICStrcpy(newProvider->providerId, sizeof(char) * NS_DEVICE_ID_LENGTH, providerId);
- NSOICFree(providerId);
- newProvider->messageUri = messageUri;
- newProvider->syncUri = syncUri;
- newProvider->accessPolicy = (NSSelector)accepter;
- newProvider->connection = connection;
-
- return newProvider;
-}
-
-OCDevAddr * NSChangeAddress(const char * address)
-{
- NS_VERIFY_NOT_NULL(address, NULL);
- OCDevAddr * retAddr = NULL;
-
- int index = 0;
- while(address[index] != '\0')
- {
- if (address[index] == ':')
- {
- break;
- }
- index++;
- }
-
- if (address[index] == '\0')
- {
- return NULL;
- }
-
- int tmp = index + 1;
- uint16_t port = address[tmp++];
-
- while(address[tmp] != '\0')
- {
- port *= 10;
- port += address[tmp++] - '0';
- }
-
- retAddr = (OCDevAddr *) OICMalloc(sizeof(OCDevAddr));
- NS_VERIFY_NOT_NULL(retAddr, NULL);
-
- retAddr->adapter = OC_ADAPTER_TCP;
- OICStrcpy(retAddr->addr, index - 1, address);
- retAddr->addr[index] = '\0';
- retAddr->port = port;
-
- return retAddr;
-}
-