OCTagsPayload* OCCopyTagsResources(const char *deviceName, const unsigned char *id, const char *baseURI, uint8_t bitmap, uint16_t port, uint8_t ins, const char *rts,const char *drel, uint32_t ttl) { OCTagsPayload *tags = (OCTagsPayload *)OICCalloc(1, sizeof(OCTagsPayload)); if (!tags) { return NULL; } if (deviceName) { tags->n.deviceName = OICStrdup(deviceName); if (!tags->n.deviceName) { goto memory_allocation_failed; } } if (id) { OICStrcpy((char*)tags->di.id, MAX_IDENTITY_SIZE, (char *)id); if (!tags->di.id) { goto memory_allocation_failed; } } if (baseURI) { tags->baseURI = OICStrdup(baseURI); if (!tags->baseURI) { goto memory_allocation_failed; } } tags->bitmap = bitmap; tags->port = port; tags->ins = ins; if (rts) { tags->rts = OICStrdup(rts); if (!tags->rts) { goto memory_allocation_failed; } } if (drel) { tags->drel = OICStrdup(drel); if (!tags->drel) { goto memory_allocation_failed; } } tags->ttl = ttl; return tags; memory_allocation_failed: OC_LOG(ERROR, TAG, "Memory allocation failed."); OCFreeTagsResource(tags); return NULL; }
OCStackResult SetPlatformInfo() { static const OCPlatformInfo platformInfo = { .platformID = "IoTivityZigbeeID", .manufacturerName = "IoTivity", .manufacturerUrl = "http://iotivity.org", .modelNumber = "T1000", .dateOfManufacture = "January 14th, 2015", .platformVersion = "0.9.2", .operatingSystemVersion = "7", .hardwareVersion = "0.5", .firmwareVersion = "0", .supportUrl = "http://iotivity.org", .systemTime = "" }; return OCSetPlatformInfo(platformInfo); } OCStackResult SetDeviceInfo() { static OCDeviceInfo deviceInfo = { .deviceName = "IoTivity/Zigbee Server Sample", .specVersion = "IoTivity/Zigbee Device Spec Version", }; char *dmv = OICStrdup("IoTivity/Zigbee Data Model Version"); deviceInfo.dataModelVersions = (OCStringLL *)OICCalloc(1, sizeof(OCStringLL)); deviceInfo.dataModelVersions->value = dmv; char *dup = OICStrdup("oic.wk.d"); deviceInfo.types = (OCStringLL *)OICCalloc(1, sizeof(OCStringLL)); deviceInfo.types->value = dup; return OCSetDeviceInfo(deviceInfo); } bool processSignal(bool set) { static sig_atomic_t signal = 0; if (set) { signal = 1; } return signal == 1; } void processCancel(int signal) { if(signal == SIGINT) { processSignal(true); } }
/* This function searches for the resource(sid:uri) in the ResourceList. * If the Resource is found in the list then it returns 0 else insert * the resource to front of the list and returns 1. */ int insertResource(const char * sid, char const * uri, const OCClientResponse * clientResponse) { ResourceNode * iter = resourceList; char * sid_cpy = OICStrdup(sid); char * uri_cpy = OICStrdup(uri); //Checking if the resource(sid:uri) is new while(iter) { if((strcmp(iter->sid, sid) == 0) && (strcmp(iter->uri, uri) == 0)) { OICFree(sid_cpy); OICFree(uri_cpy); return 0; } else { iter = iter->next; } } //Creating new ResourceNode if((iter = (ResourceNode *) OICMalloc(sizeof(ResourceNode)))) { iter->sid = sid_cpy; iter->uri = uri_cpy; iter->endpoint = clientResponse->devAddr; iter->next = NULL; } else { OC_LOG(ERROR, TAG, "Memory not allocated to ResourceNode"); OICFree(sid_cpy); OICFree(uri_cpy); return -1; } //Adding new ResourceNode to front of the ResourceList if(!resourceList) { resourceList = iter; } else { iter->next = resourceList; resourceList = iter; } return 1; }
NSResult NSProviderService::EnableRemoteService(const std::string &serverAddress) { NS_LOG(DEBUG, "EnableRemoteService - IN"); NSResult result = NSProviderEnableRemoteService(OICStrdup(serverAddress.c_str())); NS_LOG(DEBUG, "EnableRemoteService - OUT"); return result; }
CAResult_t CABleGattDiscoverCharacteristics(bt_gatt_attribute_h service, const char *remoteAddress) { OIC_LOG(DEBUG, TZ_BLE_CLIENT_TAG, "IN"); VERIFY_NON_NULL_RET(service, TZ_BLE_CLIENT_TAG, "service is NULL", CA_STATUS_FAILED); VERIFY_NON_NULL_RET(remoteAddress, TZ_BLE_CLIENT_TAG, "remoteAddress is NULL", CA_STATUS_FAILED); char *addr = OICStrdup(remoteAddress); VERIFY_NON_NULL_RET(addr, TZ_BLE_CLIENT_TAG, "Malloc failed", CA_STATUS_FAILED); int32_t ret = bt_gatt_discover_characteristics(service, CABleGattCharacteristicsDiscoveredCb, (void *)addr); // addr will be freed in callback. if (BT_ERROR_NONE != ret) { OIC_LOG_V(ERROR, TZ_BLE_CLIENT_TAG, "bt_gatt_discover_characteristics failed with error [%d]", ret); OICFree(addr); return CA_STATUS_FAILED; } OIC_LOG(DEBUG, TZ_BLE_CLIENT_TAG, "OUT"); return CA_STATUS_OK; }
CAResult_t CABleGattDiscoverServices(const char *remoteAddress) { OIC_LOG(DEBUG, TZ_BLE_CLIENT_TAG, "IN"); VERIFY_NON_NULL_RET(remoteAddress, TZ_BLE_CLIENT_TAG, "remote address is NULL", CA_STATUS_FAILED); char *addr = OICStrdup(remoteAddress); VERIFY_NON_NULL_RET(addr, TZ_BLE_CLIENT_TAG, "Malloc failed", CA_STATUS_FAILED); int32_t ret = bt_gatt_foreach_primary_services(remoteAddress, CABleGattPrimaryServiceCb, (void *)addr); // addr memory will be free in callback. if (BT_ERROR_NONE != ret) { OIC_LOG_V(ERROR, TZ_BLE_CLIENT_TAG, "bt_gatt_foreach_primary_services Failed with ret value [%d] ", ret); OICFree(addr); return CA_STATUS_FAILED; } else { OIC_LOG_V(DEBUG, TZ_BLE_CLIENT_TAG, "bt_gatt_foreach_primary_services success for address [%s]", remoteAddress); } OIC_LOG(DEBUG, TZ_BLE_CLIENT_TAG, "OUT"); return CA_STATUS_OK; }
CAResult_t CAEthernetGetInterfaceInfo(char **interfaceName, char **ipAddress) { OIC_LOG(DEBUG, ETHERNET_MONITOR_TAG, "IN"); VERIFY_NON_NULL(interfaceName, ETHERNET_MONITOR_TAG, "interface name"); VERIFY_NON_NULL(ipAddress, ETHERNET_MONITOR_TAG, "ip address"); // Get the interface and ipaddress information from cache u_mutex_lock(g_ethernetNetInfoMutex); if (g_ethernetInterfaceName == NULL || g_ethernetIPAddress == NULL) { OIC_LOG(DEBUG, ETHERNET_MONITOR_TAG, "Network not enabled"); u_mutex_unlock(g_ethernetNetInfoMutex); return CA_ADAPTER_NOT_ENABLED; } *interfaceName = (g_ethernetInterfaceName) ? strndup(g_ethernetInterfaceName, strlen(g_ethernetInterfaceName)) : NULL; *ipAddress = (g_ethernetIPAddress) ? OICStrdup((const char *)g_ethernetIPAddress) : NULL; u_mutex_unlock(g_ethernetNetInfoMutex); OIC_LOG(DEBUG, ETHERNET_MONITOR_TAG, "OUT"); return CA_STATUS_OK; }
OCRDDiscoveryPayload *OCRDDiscoveryPayloadCreate(const char *deviceName, const char *id, int biasFactor) { OCRDDiscoveryPayload *discoveryPayload = (OCRDDiscoveryPayload *)OICCalloc(1, sizeof(OCRDDiscoveryPayload)); if (!discoveryPayload) { return NULL; } if (deviceName) { discoveryPayload->n.deviceName = OICStrdup(deviceName); if (!discoveryPayload->n.deviceName) { OICFree(discoveryPayload); return NULL; } } if (id) { OICStrcpy((char*)discoveryPayload->di.id, MAX_IDENTITY_SIZE, id); } discoveryPayload->sel = biasFactor; return discoveryPayload; }
static OCStackResult appendStringLL(OCStringLL **type, const unsigned char *value) { OCStringLL *temp= (OCStringLL*)OICCalloc(1, sizeof(OCStringLL)); if (!temp) { return OC_STACK_NO_MEMORY; } temp->value = OICStrdup((char *)value); if (!temp->value) { return OC_STACK_NO_MEMORY; } temp->next = NULL; if (!*type) { *type = temp; } else { OCStringLL *tmp = *type; for (; tmp->next; tmp = tmp->next); tmp->next = temp; } return OC_STACK_OK; }
OCTagsPayload* OCCopyTagsResources(const char *deviceName, const unsigned char *id, uint64_t ttl) { OCTagsPayload *tags = (OCTagsPayload *)OICCalloc(1, sizeof(OCTagsPayload)); if (!tags) { return NULL; } if (deviceName) { tags->n.deviceName = OICStrdup(deviceName); if (!tags->n.deviceName) { goto memory_allocation_failed; } } if (id) { OICStrcpy((char*)tags->di.id, MAX_IDENTITY_SIZE, (char *)id); } tags->ttl = ttl; return tags; memory_allocation_failed: OIC_LOG(ERROR, TAG, "Memory allocation failed."); OCFreeTagsResource(tags); return NULL; }
static void OCCopyPropertyValue (OCRepPayloadValue *dest, OCRepPayloadValue *source) { if (!source || !dest) { return; } switch(source->type) { case OCREP_PROP_STRING: dest->str = OICStrdup(source->str); break; case OCREP_PROP_BYTE_STRING: dest->ocByteStr.bytes = (uint8_t*)OICMalloc(source->ocByteStr.len * sizeof(uint8_t)); VERIFY_PARAM_NON_NULL(TAG, dest->ocByteStr.bytes, "Failed allocating memory"); dest->ocByteStr.len = source->ocByteStr.len; memcpy(dest->ocByteStr.bytes, source->ocByteStr.bytes, dest->ocByteStr.len); break; case OCREP_PROP_OBJECT: dest->obj = OCRepPayloadClone(source->obj); break; case OCREP_PROP_ARRAY: OCCopyPropertyValueArray(dest, source); break; default: // Nothing to do for the trivially copyable types. break; } exit: return; }
static OCStackResult CreateStringLL(uint8_t numElements, OCResourceHandle handle, const char* (*getValue)(OCResourceHandle handle, uint8_t i), OCStringLL **stringLL) { for (uint8_t i = 0; i < numElements; ++i) { const char *value = getValue(handle, i); OIC_LOG_V(ERROR, TAG, "value: %s", value); if (!*stringLL) { *stringLL = (OCStringLL *)OICCalloc(1, sizeof(OCStringLL)); if (!*stringLL) { OIC_LOG(ERROR, TAG, "Failed allocating memory."); return OC_STACK_NO_MEMORY; } (*stringLL)->value = OICStrdup(value); if (!(*stringLL)->value) { OIC_LOG(ERROR, TAG, "Failed copying to OCStringLL."); return OC_STACK_NO_MEMORY; } } else { OCStringLL *cur = *stringLL; while (cur->next) { cur = cur->next; } cur->next = (OCStringLL *)OICCalloc(1, sizeof(OCStringLL)); if (!cur->next) { OIC_LOG(ERROR, TAG, "Failed allocating memory."); return OC_STACK_NO_MEMORY; } cur->next->value = OICStrdup(value); if (!cur->next->value) { OIC_LOG(ERROR, TAG, "Failed copying to OCStringLL."); return OC_STACK_NO_MEMORY; } } } return OC_STACK_OK; }
static void OCCopyPropertyValueArray(OCRepPayloadValue* dest, OCRepPayloadValue* source) { if (!dest || !source) { return; } size_t dimTotal = calcDimTotal(source->arr.dimensions); switch(source->arr.type) { case OCREP_PROP_INT: dest->arr.iArray = (int64_t*)OICMalloc(dimTotal * sizeof(int64_t)); VERIFY_PARAM_NON_NULL(TAG, dest->arr.iArray, "Failed allocating memory"); memcpy(dest->arr.iArray, source->arr.iArray, dimTotal * sizeof(int64_t)); break; case OCREP_PROP_DOUBLE: dest->arr.dArray = (double*)OICMalloc(dimTotal * sizeof(double)); VERIFY_PARAM_NON_NULL(TAG, dest->arr.dArray, "Failed allocating memory"); memcpy(dest->arr.dArray, source->arr.dArray, dimTotal * sizeof(double)); break; case OCREP_PROP_BOOL: dest->arr.bArray = (bool*)OICMalloc(dimTotal * sizeof(bool)); VERIFY_PARAM_NON_NULL(TAG, dest->arr.bArray, "Failed allocating memory"); memcpy(dest->arr.bArray, source->arr.bArray, dimTotal * sizeof(bool)); break; case OCREP_PROP_STRING: dest->arr.strArray = (char**)OICMalloc(dimTotal * sizeof(char*)); VERIFY_PARAM_NON_NULL(TAG, dest->arr.strArray, "Failed allocating memory"); for(size_t i = 0; i < dimTotal; ++i) { dest->arr.strArray[i] = OICStrdup(source->arr.strArray[i]); } break; case OCREP_PROP_OBJECT: dest->arr.objArray = (OCRepPayload**)OICMalloc(dimTotal * sizeof(OCRepPayload*)); VERIFY_PARAM_NON_NULL(TAG, dest->arr.objArray, "Failed allocating memory"); for(size_t i = 0; i < dimTotal; ++i) { dest->arr.objArray[i] = OCRepPayloadClone(source->arr.objArray[i]); } break; case OCREP_PROP_ARRAY: dest->arr.objArray = (OCRepPayload**)OICMalloc(dimTotal * sizeof(OCRepPayload*)); VERIFY_PARAM_NON_NULL(TAG, dest->arr.objArray, "Failed allocating memory"); for(size_t i = 0; i < dimTotal; ++i) { dest->arr.objArray[i] = OCRepPayloadClone(source->arr.objArray[i]); } break; default: OIC_LOG(ERROR, TAG, "CopyPropertyValueArray invalid type"); break; } exit: return; }
::NSMessage *NSProviderService::getNSMessage(NSMessage *msg) { ::NSMessage *nsMsg = new ::NSMessage; nsMsg->messageId = msg->getMessageId(); OICStrcpy(nsMsg->providerId, msg->getProviderId().length(), msg->getProviderId().c_str()); nsMsg->sourceName = OICStrdup(msg->getSourceName().c_str()); nsMsg->type = (::NSMessageType) msg->getType(); nsMsg->dateTime = OICStrdup(msg->getTime().c_str()); nsMsg->ttl = msg->getTTL(); nsMsg->title = OICStrdup(msg->getTitle().c_str()); nsMsg->contentText = OICStrdup(msg->getContentText().c_str()); nsMsg->mediaContents = new ::NSMediaContents; if (msg->getMediaContents() != nullptr) nsMsg->mediaContents->iconImage = OICStrdup(msg->getMediaContents()->getIconImage().c_str()); else nsMsg->mediaContents->iconImage = nullptr; return nsMsg; }
OCStackResult getZigBeeAttributesForOICResource (char * OICResourceType, AttributeList *attributeList) // GET { if (strcmp (OICResourceType, OIC_TEMPERATURE_SENSOR) == 0) { attributeList->count = 1; attributeList->list[0].oicAttribute = OICStrdup(OIC_TEMPERATURE_ATTRIBUTE); attributeList->list[0].zigBeeAttribute = ZB_TEMPERATURE_ATTRIBUTE_ID; attributeList->list[0].oicType = OIC_ATTR_DOUBLE; attributeList->list[0].zigbeeType = ZB_16_SINT; return OC_STACK_OK; } else if (strcmp (OICResourceType, OIC_DIMMABLE_LIGHT) == 0) { attributeList->count = 1; attributeList->list[0].oicAttribute = OICStrdup(OIC_DIMMING_ATTRIBUTE); attributeList->list[0].zigBeeAttribute = ZB_CURRENT_LEVEL_ATTRIBUTE_READONLY; attributeList->list[0].oicType = OIC_ATTR_INT; attributeList->list[0].zigbeeType = ZB_8_UINT; return OC_STACK_OK; } else if (strcmp (OICResourceType, OIC_CONTACT_SENSOR) == 0) { attributeList->count = 1; attributeList->list[0].oicAttribute = OICStrdup(OIC_CONTACT_ATTRIBUTE); attributeList->list[0].zigBeeAttribute = ZB_CONTACT_ATTRIBUTE_ID; attributeList->list[0].oicType = OIC_ATTR_BOOL; attributeList->list[0].zigbeeType = ZB_BOOL; return OC_STACK_OK; } else if (strcmp (OICResourceType, OIC_BINARY_SWITCH) == 0) { attributeList->count = 1; attributeList->list[0].oicAttribute = OICStrdup(OIC_ON_OFF_ATTRIBUTE); attributeList->list[0].zigBeeAttribute = ZB_ON_OFF_ATTRIBUTE_ID; attributeList->list[0].oicType = OIC_ATTR_BOOL; attributeList->list[0].zigbeeType = ZB_BOOL; return OC_STACK_OK; } return OC_STACK_ERROR; }
TEST(DoxmEntityHandlerTest, DoxmEntityHandlerValidRequest) { EXPECT_EQ(OC_STACK_INVALID_PARAM, InitDoxmResource()); char query[] = "oxm=0&owned=false&owner=owner1"; OCEntityHandlerRequest req = {0}; req.method = OC_REST_GET; req.query = OICStrdup(query); EXPECT_EQ(OC_EH_ERROR, DoxmEntityHandler(OCEntityHandlerFlag::OC_REQUEST_FLAG, &req)); OICFree(req.query); }
void CALEGattServerConnectionStateChanged(bool connected, const char *remoteAddress) { VERIFY_NON_NULL_VOID(remoteAddress, TAG, "remote address"); CAResult_t res = CA_STATUS_OK; if (connected) { OIC_LOG_V(DEBUG, TAG, "Connected to [%s]", remoteAddress); g_LEConnectedState = true; char *addr = OICStrdup(remoteAddress); oc_mutex_lock(g_LEClientListMutex); res = CAAddLEClientInfoToList(&g_LEClientList, addr); if (CA_STATUS_OK != res) { OIC_LOG(ERROR, TAG, "CAAddLEClientInfoToList failed"); oc_mutex_unlock(g_LEClientListMutex); OICFree(addr); return; } oc_mutex_unlock(g_LEClientListMutex); /* * TV Easysetup does not use IoTivity BLE advertisement. */ // res = CALEStopAdvertise(); // if (CA_STATUS_OK != res) // { // OIC_LOG_V(ERROR, TAG, "Failed to stop advertising [%d]", res); // return; // } } else { OIC_LOG_V(DEBUG, TAG, "Disconnected from [%s]", remoteAddress); g_LEConnectedState = false; oc_mutex_lock(g_LEClientListMutex); CARemoveLEClientInfoFromList(&g_LEClientList, remoteAddress); oc_mutex_unlock(g_LEClientListMutex); /* * TV Easysetup does not use IoTivity BLE advertisement. */ // res = CALEStartAdvertise(); // if (CA_STATUS_OK != res) // { // OIC_LOG_V(ERROR, TAG, "Failed to start advertising [%d]", res); // return; // } } }
NSTopicLL * NSProviderGetTopicsCacheData(NSCacheList * regTopicList) { NS_LOG(DEBUG, "NSProviderGetTopicsCache - IN"); pthread_mutex_lock(&NSCacheMutex); NSCacheElement * iter = regTopicList->head; if (!iter) { pthread_mutex_unlock(&NSCacheMutex); return NULL; } NSTopicLL * iterTopic = NULL; NSTopicLL * newTopic = NULL; NSTopicLL * topics = NULL; while (iter) { NSCacheTopicData * curr = (NSCacheTopicData *) iter->data; newTopic = (NSTopicLL *) OICMalloc(sizeof(NSTopicLL)); if (!newTopic) { pthread_mutex_unlock(&NSCacheMutex); return NULL; } newTopic->state = curr->state; newTopic->next = NULL; newTopic->topicName = OICStrdup(curr->topicName); if (!topics) { iterTopic = topics = newTopic; } else { iterTopic->next = newTopic; iterTopic = newTopic; } iter = iter->next; } pthread_mutex_unlock(&NSCacheMutex); NS_LOG(DEBUG, "NSProviderGetTopicsCache - OUT"); return topics; }
CAResult_t CAIPGetInterfaceSubnetMask(const char *ipAddress, char **subnetMask) { OIC_LOG(DEBUG, IP_MONITOR_TAG, "IN"); VERIFY_NON_NULL(subnetMask, IP_MONITOR_TAG, "subnet mask"); VERIFY_NON_NULL(ipAddress, IP_MONITOR_TAG, "ipAddress is null"); VERIFY_NON_NULL(g_networkMonitorContext, IP_MONITOR_TAG, "g_networkMonitorContext is null"); VERIFY_NON_NULL(g_networkMonitorContextMutex, IP_MONITOR_TAG, "g_networkMonitorContextMutex is null"); // Get the interface and ipaddress information from cache ca_mutex_lock(g_networkMonitorContextMutex); if (!g_networkMonitorContext->netInterfaceList || (0 == u_arraylist_length(g_networkMonitorContext->netInterfaceList))) { OIC_LOG(DEBUG, IP_MONITOR_TAG, "Network not enabled"); ca_mutex_unlock(g_networkMonitorContextMutex); return CA_ADAPTER_NOT_ENABLED; } uint32_t list_length = u_arraylist_length(g_networkMonitorContext->netInterfaceList); OIC_LOG_V(DEBUG, IP_MONITOR_TAG, "list lenght [%d]", list_length); for (uint32_t list_index = 0; list_index < list_length; list_index++) { CANetInfo_t *info = (CANetInfo_t *) u_arraylist_get( g_networkMonitorContext->netInterfaceList, list_index); if (!info) { continue; } if (strncmp(info->ipAddress, ipAddress, strlen(ipAddress)) == 0) { if (!info->subnetMask) { OIC_LOG(ERROR, IP_MONITOR_TAG, "CAIPGetInterfaceSubnetMask subnetmask is null"); } OIC_LOG_V(DEBUG, IP_MONITOR_TAG, "CAIPGetInterfaceSubnetMask subnetmask is %s", info->subnetMask); *subnetMask = info->subnetMask ? OICStrdup(info->subnetMask) : NULL; break; } } ca_mutex_unlock(g_networkMonitorContextMutex); OIC_LOG(DEBUG, IP_MONITOR_TAG, "OUT"); return CA_STATUS_OK; }
TEST(StringTests, StrdupNormalDup) { char param[] = "This is a normal parameter"; char* result = OICStrdup(param); EXPECT_TRUE(result != NULL); // ensure not the same pointer EXPECT_NE(param, result); EXPECT_STREQ(param, result); OICFree(result); }
CARemoteEndpoint_t *CAAdapterCopyRemoteEndpoint(const CARemoteEndpoint_t *remoteEndpoint) { VERIFY_NON_NULL_RET(remoteEndpoint, CA_ADAPTER_UTILS_TAG, "Remote endpoint is NULL", NULL); CARemoteEndpoint_t *info = (CARemoteEndpoint_t *) OICCalloc(1, sizeof(CARemoteEndpoint_t)); if (NULL == info) { OIC_LOG(ERROR, CA_ADAPTER_UTILS_TAG, "Memory allocation failed !"); return NULL; } info->connectivityType = remoteEndpoint->connectivityType; if (CA_EDR == info->connectivityType && strlen(remoteEndpoint->addressInfo.BT.btMacAddress)) { strncpy(info->addressInfo.BT.btMacAddress, remoteEndpoint->addressInfo.BT.btMacAddress, CA_MACADDR_SIZE - 1); info->addressInfo.BT.btMacAddress[CA_MACADDR_SIZE - 1] = '\0'; } else if (CA_LE == info->connectivityType && strlen(remoteEndpoint->addressInfo.LE.leMacAddress)) { strncpy(info->addressInfo.LE.leMacAddress, remoteEndpoint->addressInfo.LE.leMacAddress, CA_MACADDR_SIZE - 1); info->addressInfo.LE.leMacAddress[CA_MACADDR_SIZE - 1] = '\0'; } else if ((CA_WIFI == info->connectivityType || CA_ETHERNET == info->connectivityType) && strlen(remoteEndpoint->addressInfo.IP.ipAddress)) { strncpy(info->addressInfo.IP.ipAddress, remoteEndpoint->addressInfo.IP.ipAddress, CA_IPADDR_SIZE - 1); info->addressInfo.IP.ipAddress[CA_IPADDR_SIZE - 1] = '\0'; info->addressInfo.IP.port = remoteEndpoint->addressInfo.IP.port; } else { OIC_LOG(DEBUG, CA_ADAPTER_UTILS_TAG, "Its not matching. May be multicast."); } //For Multicast, remote address will be null while resourceUri will have the service UUID if (remoteEndpoint->resourceUri && strlen(remoteEndpoint->resourceUri)) { info->resourceUri = OICStrdup(remoteEndpoint->resourceUri); } info->isSecured = remoteEndpoint->isSecured; return info; }
CARemoteEndpoint_t *CAAdapterCreateRemoteEndpoint(CAConnectivityType_t type, const char *address, const char *resourceUri) { CARemoteEndpoint_t *info = (CARemoteEndpoint_t *) OICCalloc(1, sizeof(CARemoteEndpoint_t)); if (NULL == info) { OIC_LOG(ERROR, CA_ADAPTER_UTILS_TAG, "Memory allocation failed !"); return NULL; } info->connectivityType = type; if (address && strlen(address)) { if (CA_EDR == type) { strncpy(info->addressInfo.BT.btMacAddress, address, CA_MACADDR_SIZE - 1); info->addressInfo.BT.btMacAddress[CA_MACADDR_SIZE - 1] = '\0'; } else if (CA_LE == type) { strncpy(info->addressInfo.LE.leMacAddress, address, CA_MACADDR_SIZE - 1); info->addressInfo.LE.leMacAddress[CA_MACADDR_SIZE - 1] = '\0'; } else if (CA_WIFI == type || CA_ETHERNET == type) { strncpy(info->addressInfo.IP.ipAddress, address, CA_IPADDR_SIZE - 1); info->addressInfo.IP.ipAddress[CA_IPADDR_SIZE - 1] = '\0'; } else { OIC_LOG(ERROR, CA_ADAPTER_UTILS_TAG, "type is not matched with any transport!"); OICFree(info); return NULL; } } if (resourceUri && strlen(resourceUri)) { info->resourceUri = OICStrdup(resourceUri); } return info; }
OCEntityHandlerRequest *CopyRequest(OCEntityHandlerRequest *entityHandlerRequest) { OC_LOG(INFO, TAG, "Copying received request for slow response"); OCEntityHandlerRequest *copyOfRequest = (OCEntityHandlerRequest *)OICMalloc(sizeof(OCEntityHandlerRequest)); if (copyOfRequest) { // Do shallow copy memcpy(copyOfRequest, entityHandlerRequest, sizeof(OCEntityHandlerRequest)); if (copyOfRequest->query) { copyOfRequest->query = OICStrdup(entityHandlerRequest->query); if(!copyOfRequest->query) { OC_LOG(ERROR, TAG, "Copy failed due to allocation failure"); OICFree(copyOfRequest); return NULL; } } if (entityHandlerRequest->payload) { copyOfRequest->payload = reinterpret_cast<OCPayload*> (OCRepPayloadClone ((OCRepPayload*) entityHandlerRequest->payload)); } // Ignore vendor specific header options for example copyOfRequest->numRcvdVendorSpecificHeaderOptions = 0; copyOfRequest->rcvdVendorSpecificHeaderOptions = NULL; } if (copyOfRequest) { OC_LOG(INFO, TAG, "Copied client request"); } else { OC_LOG(ERROR, TAG, "Error copying client request"); } return copyOfRequest; }
void CAEDRGetLocalAddress(char **address) { bool isAttached = false; JNIEnv* env; jint res = (*g_jvm)->GetEnv(g_jvm, (void**) &env, JNI_VERSION_1_6); if (JNI_OK != res) { OIC_LOG(DEBUG, TAG, "CAEDRGetLocalAddress - Could not get JNIEnv pointer"); res = (*g_jvm)->AttachCurrentThread(g_jvm, &env, NULL); if (JNI_OK != res) { OIC_LOG(ERROR, TAG, "AttachCurrentThread failed"); return; } isAttached = true; } jstring jni_address = CAEDRNativeGetLocalDeviceAddress(env); if (jni_address) { const char* localAddress = (*env)->GetStringUTFChars(env, jni_address, NULL); *address = OICStrdup(localAddress); if (*address == NULL) { if (isAttached) { (*g_jvm)->DetachCurrentThread(g_jvm); } (*env)->ReleaseStringUTFChars(env, jni_address, localAddress); (*env)->DeleteLocalRef(env, jni_address); return; } (*env)->ReleaseStringUTFChars(env, jni_address, localAddress); (*env)->DeleteLocalRef(env, jni_address); } OIC_LOG_V(DEBUG, TAG, "Local Address : %s", *address); if (isAttached) { (*g_jvm)->DetachCurrentThread(g_jvm); } }
OCStackResult BuildVirtualCollectionResourceResponse(const OCResourceCollectionPayload *resourcePtr, OCDiscoveryPayload *payload, OCDevAddr *devAddr) { if (!resourcePtr || !payload) { return OC_STACK_INVALID_PARAM; } if (resourcePtr->tags && (resourcePtr->tags->bitmap & OC_SECURE)) { if (GetSecurePortInfo(devAddr, &resourcePtr->tags->port) != OC_STACK_OK) { OC_LOG(ERROR, TAG, "Failed setting secure port."); } } if (resourcePtr->tags && !resourcePtr->tags->baseURI) { resourcePtr->tags->baseURI = OICStrdup(devAddr->addr); } OCDiscoveryCollectionPayloadAddResource(payload, resourcePtr->tags, resourcePtr->setLinks); return OC_STACK_OK; }
OCStackResult ZigbeeInit(const char * comPort, PIPlugin_Zigbee ** plugin, PINewResourceFound newResourceCB) { if(!plugin) { return OC_STACK_INVALID_PARAM; } *plugin = (PIPlugin_Zigbee *) OICMalloc(sizeof(PIPlugin_Zigbee) + sizeof(PIPluginBase)); if(!*plugin) { return OC_STACK_NO_MEMORY; } ((*plugin)->header).type = PLUGIN_ZIGBEE; ((*plugin)->header).comPort = OICStrdup(comPort); ((*plugin)->header).NewResourceFoundCB = newResourceCB; ((*plugin)->header).next = NULL; ((*plugin)->header).resourceList = NULL; ((*plugin)->header).processEHRequest = ProcessEHRequest; gPlugin = plugin; return TWInitialize(comPort); }
OCRDDiscoveryPayload *OCRDDiscoveryPayloadCreate(const char *deviceName, const char *id, int biasFactor) { OCRDDiscoveryPayload *discoveryPayload = (OCRDDiscoveryPayload *)OICCalloc(1, sizeof(OCRDDiscoveryPayload)); VERIFY_PARAM_NON_NULL(TAG, discoveryPayload, "Failed allocating memory for discovery payload"); if (deviceName) { discoveryPayload->n.deviceName = OICStrdup(deviceName); VERIFY_PARAM_NON_NULL(TAG, discoveryPayload->n.deviceName, "Failed allocating memory for discovery device name"); } if (id) { OICStrcpy((char*)discoveryPayload->di.id, MAX_IDENTITY_SIZE, id); } discoveryPayload->sel = biasFactor; return discoveryPayload; exit: OICFree(discoveryPayload); discoveryPayload = NULL; return discoveryPayload; }
static void OCCopyPropertyValue (OCRepPayloadValue *dest, OCRepPayloadValue *source) { if (!source || !dest) { return; } switch(source->type) { case OCREP_PROP_STRING: dest->str = OICStrdup(source->str); break; case OCREP_PROP_OBJECT: dest->obj = OCRepPayloadClone(source->obj); break; case OCREP_PROP_ARRAY: OCCopyPropertyValueArray(dest, source); break; default: // Nothing to do for the trivially copyable types. break; } }
int oic_log_set_module(oic_log_ctx_t *ctx, const char *module_name) { char *mn; if (0 == ctx) return 0; /* Swap pointers so that module data's not erased in the event of failure: */ mn = OICStrdup(module_name); if (0 == mn) { if (0 != ctx->module_name) free(ctx->module_name); return 0; } if (0 != ctx->module_name) free(ctx->module_name); ctx->module_name = mn; /* Notify: */ return ctx->set_module(ctx, ctx->module_name); }
static void OCCopyPropertyValueArray(OCRepPayloadValue* dest, OCRepPayloadValue* source) { size_t dimTotal = calcDimTotal(source->arr.dimensions); switch(source->arr.type) { case OCREP_PROP_INT: dest->arr.iArray = (int64_t*)OICMalloc(dimTotal * sizeof(int64_t)); memcpy(dest->arr.iArray, source->arr.iArray, dimTotal * sizeof(int64_t)); break; case OCREP_PROP_DOUBLE: dest->arr.dArray = (double*)OICMalloc(dimTotal * sizeof(double)); memcpy(dest->arr.dArray, source->arr.dArray, dimTotal * sizeof(double)); break; case OCREP_PROP_BOOL: dest->arr.bArray = (bool*)OICMalloc(dimTotal * sizeof(bool)); memcpy(dest->arr.bArray, source->arr.bArray, dimTotal * sizeof(bool)); break; case OCREP_PROP_STRING: dest->arr.strArray = (char**)OICMalloc(dimTotal * sizeof(char*)); for(size_t i = 0; i < dimTotal; ++i) { dest->arr.strArray[i] = OICStrdup(source->arr.strArray[i]); } break; case OCREP_PROP_ARRAY: dest->arr.objArray = (OCRepPayload**)OICMalloc(dimTotal * sizeof(OCRepPayload*)); for(size_t i = 0; i < dimTotal; ++i) { dest->arr.objArray[i] = OCRepPayloadClone(source->arr.objArray[i]); } break; default: OC_LOG(ERROR, TAG, PCF("CopyPropertyValueArray invalid type")); break; } }